views:

233

answers:

3

I am trying to write my watir script to grab the following data (the table body headers and the table row data, but I am having trouble trying to figure out how to access the table. (Once I get that, teh rest is a piece of cake).

Can anyone come up with something that will help me access the table? It doesn't have a name or an ID...

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

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

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

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

marc
awesome... this was perfect...
NinjaCat
+2  A: 

But wait, there is more! :)

browser.div(id => "income").table(:class => 'tHe')
browser.div(id => "income").table(:index => 1)
...
Željko Filipin
Thanks for this... I am actually going to be able to use this for the same project, just in a different area...
NinjaCat
+2  A: 

There is also XPath if you are stuck.

If you fire up the page and access it through Firebug or your browser's native developer tools, you can find the xpath expression for the table and then plug that into the Watir API call.

I think it was in later versions of Watir 1.5.x that support for advanced page querying came in (basically your problem, where there are no ID tags). This page on the watir wiki should help: Ways Available To Identify HTML Element

Richard Conroy