Selenium IDE 和 xpath - 在表格中查找文本/行并选择单选框
我一直在使用 Selenium IDE 并获得了一些不错的结果.我已经阅读了很多关于后续兄弟姐妹和前兄弟姐妹的文章,但我找不到正确的单选按钮.
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.
本质上,我想在表格中找到带有testing"一词的行,然后单击单元格中的单选按钮.
Essentially I want to find the row in a table with the word 'testing' and then click the radio button in the cell.
到目前为止我能找到输入按钮//输入[@type='radio']
So far I can find the input button //input[@type='radio']
并找到文本测试//a[contains(text(),'testing')]
and find the text testing //a[contains(text(),'testing')]
我一直在尝试在ide中使用它
I've been trying to use this in the ide
check | //input[@type='radio']/following-sibling::td[1]/a[contains(text(),'testing')]
但我收到错误 [error] locator not found://input[@type='radio']/following-sibling::a[contains(text()[1],'testing')]
非常感谢任何改变这一点的帮助:)
Any help to change this is really appreciated :)
干杯
达米安
这是基本的表格...
<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>
你的 xpath 的问题是 td
和 input
不是 兄弟 (它们没有共同的父级),即使您将 xpath 更改为更正确的版本:
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')]
它会找到带有前面复选框的 a
而不是复选框本身.所以正确的 xpath 将是:
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]
或
//tr[descendant::a[contains(.,'testing')]]//input[@type='radio']
有关 xpath 轴教程,请阅读:http://msdn.microsoft.com/en-us/library/ms256456.aspx
For xpath axis tutorial read this: http://msdn.microsoft.com/en-us/library/ms256456.aspx