I've got code for a table header:
<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>
and need to find how many th tags has class "disabledHeader" or at least get class of a particular (addressed by id).
When I do:
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]
or cl(:class)
return errors.
b.element(:class, "disabledHeader").size
returns method missing error.
How to address all the th-s
of this class?
nokogiri
. – Muggyb.element(:class, "disabledHeader").size
is returning a missing method error since you usedelement
.size
is only available for element collections, so you need to haveelements
(ie pluralized). Since you know they areth
elements, you should be more specific as in Zeljko's answer. – Fayinab.ths(:class, "disabledHeader").size
returns me 0? – Eaton