如何在 selenium IDE 中识别输入后跟标签?

发布于 2024-11-09 09:05:27 字数 511 浏览 0 评论 0原文

我必须使用其后面的标签来识别复选框。 代码如下:

<input type="checkbox" checked="" value="1" id="email-100-100" name="email-100-100">
<label for="email-100-100" class="firefinder-match">Email me when someone asks me to set a flag</label>
<br>
</td>

我尝试了

Target://following-sibling::label[text()="当有人要求我设置标志时给我发送电子邮件"] Target://preceding-sibling::label[text()="当有人要求我设置标志时给我发电子邮件"]

但在这两种情况下,selenium 都会找到标签的文本,但找不到复选框。

有人可以帮我吗?

先感谢您

I have to identify a check-box using the label which follows it.
the code is the following:

<input type="checkbox" checked="" value="1" id="email-100-100" name="email-100-100">
<label for="email-100-100" class="firefinder-match">Email me when someone asks me to set a flag</label>
<br>
</td>

I tried

Target://following-sibling::label[text()="Email me when someone asks me to set a flag"]
Target://preceding-sibling::label[text()="Email me when someone asks me to set a flag"]

but in both cases selenium finds the text of label but not the check-box.

Could somebody help me in this?

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

流年里的时光 2024-11-16 09:05:27

尝试一下即可。

Target://label[text()="Email me when someone asks me to set a flag"]/../input[@type='checkbox']

只要标签和复选框的包含元素只有一个复选框,

Try

Target://label[text()="Email me when someone asks me to set a flag"]/../input[@type='checkbox']

It will work as long as the containing element of the label and checkbox only has one checkbox in it.

慵挽 2024-11-16 09:05:27

您还可以找到包含文本的标签,这对于部分匹配很有用。就我而言,我有这样的情况:

<label for="blah">
     <input name="blah" id="blah" type="checkbox" />
     Store Locator Plus
</label>

接受的解决方案适用于引用的特定示例,但需要完全匹配。由于这出现在搜索结果的顶部,我想我也应该在这里介绍部分匹配解决方案。

对于 Selenium IDE,您可以设置如下目标:

//label[contains(text(),'Store Locator Plus')]//input[@type="checkbox"]

需要 contains 函数,因为标签文本也有一个 HTML 元素,这阻碍了 //label[text()='Store Locator Plus'] 目标。

You can also find a label that contains text, which is useful for a partial match. In my case I had something like this:

<label for="blah">
     <input name="blah" id="blah" type="checkbox" />
     Store Locator Plus
</label>

The accepted solution worked for the specific example cited but requires an exact match. Since this comes up on the top of search results I figured I'd present the partial-match solution here as well.

For Selenium IDE you can set a target like this:

//label[contains(text(),'Store Locator Plus')]//input[@type="checkbox"]

The contains function was required because the label text had an HTML element as well which thwarted the //label[text()='Store Locator Plus'] target.

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