David542
David542

Reputation: 110592

Deducing an html element via its adjacent values

I have an html page that renders something similar to the following table:

nov.    service 1     [ click to download pdf ]
nov.    service 5     [ click to download pdf ]
nov.    service 3     [ click to download pdf ]
dec.    service 1     [ click to download pdf ]
dec.    service 9     [ click to download pdf ]

This is the html:

<tr class="values">
    <td class="col-1 first">Nov 2011</td>
    <td class="col-2">Switzerland</td>
    <td class="col-4">7</td>
    <td class="col-5">24.56</td>
    <td class="col-6">CHF</td>
    <input width="65" height="16" type="image" name="0.0.9.7.3.1.11.1.11.17.1.8.13.1.1" src="/itc/images/btn-grey-download.png" /></td>
</tr>
<tr class="values">
    <td class="col-1 first">Nov 2011</td>
    <td class="col-2">United Kingdom</td>
    <td class="col-4">25</td>
    <td class="col-5">67.88</td>
    <td class="col-6">GBP</td>
    <input width="65" height="16" type="image" name="0.0.9.7.3.1.11.1.11.17.1.9.13.1.1" src="/itc/images/btn-grey-download.png" />
</tr>
<tr class="values">
    <td class="col-1 first">Oct 2011</td>
    <td class="col-2">Americas</td>
    <td class="col-4">14</td>
    <td class="col-5">2</td>
    <td class="col-6">USD</td>
    <input width="65" height="16" type="image" name="0.0.9.7.3.1.11.1.11.17.1.10.13.1.1" src="/itc/images/btn-grey-download.png" />
</tr>

I need to be able to 'select' and click all buttons that are in the month of nov (currently I'm using Selenium). I'm able to click a single button via the CSS selector (figured out through Firebug), but how would I do programmatically for all buttons in the month of nov? The psuedocode would be:

if tr.values.col-1.startswith(<month>):
    click the button in that row

Upvotes: 0

Views: 88

Answers (1)

Jeremiah Orr
Jeremiah Orr

Reputation: 2630

Since you're using Selenium, you may want to try selecting by XPath instead. This XPath expression will give you all the <input> elements in a row with Nov 2011 in the first column:

//td[@class='col-1 first']/text()[normalize-space()='Nov 2011']/parent::*/parent::*/td/input

Upvotes: 1

Related Questions