watirfirewatir

Watir: How to access a table without an ID or NAME


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

Solution

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