ear*_*ter 5 ruby watir-webdriver
我有表头的代码:
<thead>
<tr class="ui-jqgrid-labels ui-sortable" role="rowheader" style="">
<th id="categories_formName" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 250px;">
<div id="jqgh_categories_formName" class="ui-jqgrid-sortable">Category Name</div>
</th>
<th id="categories_totalClicks" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 99px;">
<div id="jqgh_categories_totalClicks" class="ui-jqgrid-sortable">Clicks</div>
</th>
<th id="categories_avgCpc" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 99px;">
<div id="jqgh_categories_avgCpc" class="ui-jqgrid-sortable">Avg CPC($)</div>
</th>
<th id="categories_totalCost" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr" style="width: 99px;">
<div id="jqgh_categories_totalCost" class="ui-jqgrid-sortable">Total Cost($)</div>
</th>
<th id="categories_convertToSale" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr disabledHeader" style="width: 99px;">
<div id="jqgh_categories_convertToSale" class="ui-jqgrid-sortable">CTS(%)</div>
</th>
<th id="categories_totalOrders" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr disabledHeader" style="width: 99px;">
<div id="jqgh_categories_totalOrders" class="ui-jqgrid-sortable">Total Orders</div>
</th>
<th id="categories_totalSales" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr disabledHeader" style="width: 99px;">
<div id="jqgh_categories_totalSales" class="ui-jqgrid-sortable">Sales($)</div>
</th>
<th id="categories_costOfSale" role="columnheader" class="ui-state-default ui-th-column ui-th-ltr disabledHeader" style="width: 96px;">
<div id="jqgh_categories_costOfSale" class="ui-jqgrid-sortable">COS(%)</div>
</th>
</tr>
Run Code Online (Sandbox Code Playgroud)
并且需要找到有多少个标签有类"disabledHeader"或至少得到一个特定的类(由id寻址).
当我做:
cl = b.th(:xpath, '//th[@id="categories_convertToSale"]')
cl.exist?
=> true
cl.inspect
=> "#<Watir::TableHeaderCell:0x..f9b976cc1015b866a located=true selector={:xpath=>\"//th[@id=\\\"categories_convertToSale\\\"]\", :tag_name=>\"th\"}>"
cl.class
=> Watir::TableHeaderCell
Run Code Online (Sandbox Code Playgroud)
cl[@class]或cl(:class)返回错误.
b.element(:class, "disabledHeader").size 返回方法缺少错误.
如何解决th-s这个课程的所有问题?
Chu*_*den 10
Zeljko解决了关于计算与某些模式匹配的标签数量的问题.
关于获得某类东西,这取决于你所指的"阶级"的味道.
Ruby类
Ruby是一种面向对象的语言,对象由语言中的"class"关键字定义.Watir使用它,并且具有与HTML对象平行的内部对象模型.在Ruby中,.class方法返回一个对象的类,它被硬连线到该语言中.(实际上你不会.class在watir rDocs中看到任何描述的方法)当你尝试看起来像这样的代码时,你正在做的事情
b.th(:id => "categories_convertToSale").class
Run Code Online (Sandbox Code Playgroud)
=> Watir :: TableHeaderCell
它告诉你该.th方法返回的对象类是watir'TableHeaderCell'(有关更多信息,请参阅TableHeaderCell 对象 和/或.th方法的watir rdoc )
HTML类属性
"class"的另一种风格是HTML类属性,它是HTML中几乎所有元素类型的标准属性.要实现这一点,您需要使用watir的.attribute_value方法以及要检查的属性,获取元素的属性值,或者watir中的任何对象,例如与HTML元素类型平行的TableHeaderCell.
b.th(:id => "categories_totalCost").attribute_value("class")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6454 次 |
| 最近记录: |