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

发布于 2024-12-22 21:07:12 字数 431 浏览 2 评论 0原文

好的,考虑到以下情况:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路还长,别太狂 2024-12-29 21:07:12

使用 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.

剪不断理还乱 2024-12-29 21:07:12

您需要一个区分这两个按钮的 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'".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文