I've been using Selenium IDE and getting some good results. I've done a lot of reading about following-sibling and preceding-sibling but I can't locate the right radio button.
Essentially I want to find the row in a table with the word 'testing' and then click the radio button in the cell.
So far I can find the input button //input[@type='radio']
and find the text testing //a[contains(text(),'testing')]
I've been trying to use this in the ide
check | //input[@type='radio']/following-sibling::td[1]/a[contains(text(),'testing')]
but I get the error [error] locator not found: //input[@type='radio']/following-sibling::a[contains(text()[1],'testing')]
Any help to change this is really appreciated :)
Cheers
Damien
here's the bare basic table ...
<tbody id="list">
<tr>
<th>
<label class="radio">
<input class="presentation_radio" type="radio" value="1" name="presentation_radio">
</label>
</th>
<td>
<a href="/link_to/document">testing </a>
</td>
<td>testing</td>
<td>Joe Acme</td>
<td>Presentation</td>
<td>03 May 2012</td>
<td>5 (1)</td>
</tr>
</tbody>
The problem with your xpath is that td
and input
are not sibling (they don't have common parent) and even if you change your xpath to more correct version:
//input[@type='radio']/following::td[1]/a[contains(text(),'testing')]
it will find a
that have preceding checkbox instead of checkbox itself. So correct xpath will be:
//a[contains(text(),'testing')]/preceding::input[@type='radio'][1]
or
//tr[descendant::a[contains(.,'testing')]]//input[@type='radio']
For xpath axis tutorial read this: http://msdn.microsoft.com/en-us/library/ms256456.aspx
来源:https://stackoverflow.com/questions/10428878/selenium-ide-and-xpath-find-text-row-in-table-and-select-radio-box