如何使Selenium根据表格中的文字单击右侧的单选按钮?

时间:2011-12-23 11:14:57

标签: selenium radio-button bdd selenium-webdriver

好的,考虑到以下情况:

<tr>
   <td> input="the wrong radio button" </td>
   <td> the wrong title </td>
</tr>
<tr>
   <td> input="the right radio button" </td>
   <td> the right title </td>
</tr>

我已将“正确的标题”存储在变量中。如何让Selenium单击右侧的单选按钮?

无线电具有动态ID(例如foo_bar_4711),它们与标题没有直接关系。

我需要“点击tr中的单选按钮,其中包含您正在寻找的文本的td”。

2 个答案:

答案 0 :(得分:3)

使用xpath,类似//td[contains(text(),'the right title')]/../td[1]。关键是使用..返回树中的一个级别。

答案 1 :(得分:1)

您需要一个XPath定位器来区分这两个按钮。像xpath=tr[td[.='the right title']]//input这样的东西。在英语中,这意味着“包含在表格单元格中的输入按钮,该表格单元格的文本是'正确的标题'”。