then the Watir-webdriver Automation test scheme and implementation based on Ruby (Iv.)Http://www.cnblogs.com/Javame/p/4164570.html 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.
Http://www.cnblogs.com/Javame/p/4164471.html
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.
2.xpath
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'
D.text
Case TWO:
A = B.A (:xpath=>"//*[@id = ' blacklisttable ']/tbody/tr/td[4]/a"). Textputs a
Case THREE:
Value = Ie.link (: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)