我有一个表头的代码:

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

并且需要查找有多少个标签具有“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
cl[@class]cl(:class)返回错误。
b.element(:class, "disabledHeader").size返回方法丢失错误。

如何解决此类的所有th-s

最佳答案

这应该做到这一点:

browser.ths(:class => "disabledHeader").size

关于ruby - 如何在ruby/watir中获取元素的类?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16043788/

10-16 13:15