Ruby-based watir-webdriver Automated Testing Solution and implementation (5), watirwebdriver

Source: Internet
Author: User
Tags xpath contains

Ruby-based watir-webdriver Automated Testing Solution and implementation (5), watirwebdriver
Then the Ruby-based watir-webdriver Automated Testing Solution and Implementation (4)Http://www.cnblogs.com/javame/p/4164570.htmlcontinue ...... for special control capturing, exception Control Analysis, and various attribute capturing methods on the page. This section describes how to extract the desired data on the browser page as a parameter and transfer it to Tools for comparison with the data in the database/linux. Many of my friends have asked the following questions:

<Div class = "button-div"> <input type = "hidden" name = "act" value = "insert"> <input type = "hidden" name = "old_title" value = ""> <input type = "hidden" name = "id" value = ""> <input type = "submit" value = "OK" class = "button"> <input type = "reset" value = "reset" class = "button"> </div>

@ B. button (: name => "button"). Why can't I click it?

Or how to capture multi-layer controls:

 

In fact, we will introduce the Ruby-based watir-webdriver Automated Testing Solution and implementation (3). Here we will discuss it in detail.

Http://www.cnblogs.com/Javame/p/4164471.html

Watir-webdriver provides two methods for capturing such controls:

1. Recursion

We can step-by-step positioning from the parent level. We can start with the first div,

@@b.div(:class=>"").divs[3].spans[0]....

@ B. dv is the parent level, and divs [3] is the fourth div below the parent level. Remember the difference between watir-webdriver and watir. The array subscript starts from 0 and watir starts from 1.

Spans [0] is the first span under the fourth div below the parent level, so that the first level is located down.

2. xpath

Xpath is simple. chrome provides the xpath capture tool.

We only need to use it in the code, for example:

@@b.a(:xpath=>"//*[@id='blackListTable']/tbody/tr/td[4]/a").click@@b.div(:class=>"detail").inputs[1].click

The original xpath contains double quotation marks:

//*[@id="blackListTable"]/tbody/tr/td[4]/a 

Note that double quotation marks are enclosed in single quotation marks and single quotation marks are enclosed in double quotation marks. This is a law!

After the special controls and abnormal behaviors are finished, let's talk about page element capturing.

For example, our blog homepage

I want to extract the word "look for it". How can this problem be solved?

In fact, watir-webdriver provides the ". text" execution event. Check the Code:

Case 1:

d = b.div :class => 'ss-form-desc ss-no-ignore-whitespace'
puts d.text

Case 2:

a = b.a(:xpath=>"//*[@id='blackListTable']/tbody/tr/td[4]/a").textputs a

Case 3:

Value = ie.link(:id=>’xxx’).attribute_value(“href”)

PS a careful:

In many cases, some controls are hidden and some events need to be promoted for display. For example:

The delete button is displayed only when you trigger a mouse click or move event. If ruby is not triggered, an exception or error occurs.

Based on the above information, we can design and implement the following:

# Click the div with the simulated mouse to trigger the deletion of the control...
B. div (: class => "detail"). inputs [1]. click # click to delete B. button (: class => "deleteBtn"). click

O (startup _ startup) o Haha, Do you think automatic writing is a little simple...

 



 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.