如何使Selenium根据表格中的文本单击正确的单选按钮? [英] How to make Selenium click the right radio button based on text in table?
问题描述
好吧,考虑到以下情况:
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>
我已经在一个变量中存储了正确的标题".如何使Selenium单击右侧的单选按钮?
I have "the right title" already stored in a variable. How can I make Selenium click the right radio button?
收音机的动态ID(例如foo_bar_4711)与标题没有直接关系.
The radios have dynamic id´s (e.g. foo_bar_4711) that aren ´t directly related with the title.
我需要类似在tr中单击包含要查找的文本的td的单选按钮"之类的东西.
I would need something like "click the radio button in the tr that containts a td having the text you are looking for".
推荐答案
您需要一个区分两个按钮的XPath定位器. xpath=tr[td[.='the right title']]//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'".
这篇关于如何使Selenium根据表格中的文本单击正确的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!