如何让 Selenium 根据表格中的文本单击右侧的单选按钮?
好的,考虑到以下情况:
<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”。
Okay, given the following situation:
<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>
I have "the right title" already stored in a variable. How can I make Selenium click the right radio button?
The radios have dynamic id´s (e.g. foo_bar_4711) that aren ´t directly related with the title.
I would need something like "click the radio button in the tr that containts a td having the text you are looking for".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 xpath,例如
//td[contains(text(),'the right title')]/../td[1]
。关键是使用..
在树中返回上一级。Use xpath, something like
//td[contains(text(),'the right title')]/../td[1]
. The key is to use..
to go back up one level in the tree.您需要一个区分这两个按钮的 XPath 定位器。类似
xpath=tr[td[.='正确的标题']]//input
。在英语中,这意味着“表格行中包含的输入按钮,该行包含文本为“正确标题”的表格单元格”。You need an XPath locator that differentiates between the two buttons. Something like
xpath=tr[td[.='the right title']]//input
. In English, that means "the input button contained within the table row that contains a table cell who's text is 'the right title'".