Then the Watir-webdriver Automation test scheme and implementation based on Ruby (v)

Source: Internet
Author: User
Tags xpath

then the Watir-webdriver Automation test scheme and implementation based on Ruby (Iv.)Http:// continue ... About special control captures, exception control analysis, how to capture the various properties of a page. This section tells you how to extract the data we want as parameters in the browser page and pass it to tools to do a comparison with the database/linux data. A lot of friends have asked these questions before:
<divclass="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="Determine" class="Button"> <input type="Reset"Value=" Reset" class="Button"> </div>

@@b.button (:name=> "button"). Click Why not?

Or a control that encapsulates a lot of layers how to capture:

In fact, in the Ruby-based Watir-webdriver Automation testing program and implementation (iii), described in detail here.


For how such controls are captured, Watir-webdriver provides two ways to capture them:

1. Recursive type

We can move from parent to child, and we can start with the first Div,

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

@@b.dv is the parent, Divs[3] is the fourth Div below the parent, remembering Watir-webdriver difference with Watir, array subscript starting from 0, and Watir starting from 1.

Spans[0] is the first span below the fourth DIV below the parent, so it is positioned down one level.


XPath is simple, and chrome itself provides the XPath capture tool

We just need to use it in our code, for example:

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

The original XPath is enclosed in double quotes:


Note that the double quotation marks enclose the single quotation mark, enclose the double quotation mark inside the quotation mark, this is the law!

Special controls and abnormal behavior are finished, and then we will talk about the problem of page element capture.

For example, our blog Garden Home

I want to extract the "Look for" these three words, how to solve?

In fact, Watir-webdriver provides the ". Text" execution event, see the code:

Case one:

D = b.div:class'ss-form-desc ss-no-ignore-whitespace'

Case TWO:

A = B.A (:xpath=>"//*[@id = ' blacklisttable ']/tbody/tr/td[4]/a"). Textputs a


Value = (:id=> ' xxx '). Attribute_value ("href")

PS A small experience:

In many cases, some controls are hidden and require certain events to be displayed, such as:

The Delete button is required to trigger a mouse click or move event to be displayed, and if not triggered Ruby will prompt an exception error.

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

#模拟鼠标在改div上点击一下, do you want to trigger the delete control?
B.div (:Class="detail"). inputs[1].click# Click Delete B.button (: Class="deletebtn"). Click

O (∩_∩) o haha, is not beginning to think that automation is beginning to write some simple ...

Next Ruby-based Watir-webdriver automation test scenario and implementation (V)

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: 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.