Watir: How to access a table without ID or NAME

I am trying to write my watir script to capture the following data (table body headers and table row data, but I had problems trying to figure out how to access the table. (As soon as I get this, the rest is a piece of cake).

Can someone come up with something to help me access the table? It does not have a name or identifier ...

<div id="income"> <table class="tHe" cellspacing="0"> <thead> <tr> <th id="companyLabel" class="tFirst" style="width:30%"> Quarter Ending </th> <th id="201004" class="tFirst right">Apr&nbsp;10 </th> <th id="201001" class="tFirst right">Jan&nbsp;10 </th> <th id="200910" class="tFirst right">Oct&nbsp;09 </th> <th id="200907" class="tFirst right">Jul&nbsp;09 </th> <th id="200904" class="tFirst right">Apr&nbsp;09 </th> </tr> </thead> <tbody id="revenueBody"> <tr> <td class="indtr">Totals</dfn></td> <td class="right">2849.00</td> <td class="right">3177.00</td> <td class="right">5950.00</td> <td class="right">4451.00</td> <td class="right">3351.00</td> </tr> ... 
+4
source share
3 answers

ie.table (: class => 'tHe') should work if there are no other tables with the same class name

ie.table (: after ?, ie.div (: id, 'income')) should work if there is no other div with id 'income'

or ie.table (: index => 0) - you will need to check your page to find out what is the correct index value for your table.

+6
source

But wait, more! :)

 browser.div(:id => "income").table(:class => 'tHe') browser.div(:id => "income").table(:index => 1) ... 
+5
source

There is also XPath if you are stuck.

If you run the page and access it through Firebug or your own developer tools, you can find the xpath expression for the table and then connect it to the Watir API call.

I think that in later versions of Watir 1.5.x, support for advanced page request has appeared (mainly your problem where there are no identification tags). This wiki page should help: Ways to define an HTML element

+3
source

All Articles