如何在 selenium IDE 中识别输入后跟标签?
我必须使用其后面的标签来识别复选框。 代码如下:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下即可。
只要标签和复选框的包含元素只有一个复选框,
Try
It will work as long as the containing element of the label and checkbox only has one checkbox in it.
您还可以找到包含文本的标签,这对于部分匹配很有用。就我而言,我有这样的情况:
接受的解决方案适用于引用的特定示例,但需要完全匹配。由于这出现在搜索结果的顶部,我想我也应该在这里介绍部分匹配解决方案。
对于 Selenium IDE,您可以设置如下目标:
需要 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:
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:
The contains function was required because the label text had an HTML element as well which thwarted the //label[text()='Store Locator Plus'] target.