使用 :text 使用 watir-webdriver 定位 LI 元素
我试图找到并单击 jQuery 菜单元素,该菜单被定义为包含多个 LI 元素的多个 UL 元素。
在我使用过的标准 WATIR 中,在 Mac 10.5 上使用 Firefox 3.6.17;
browser.li(:text,"Options...").click
或者
browser.div(:id,"Attributes-menu").li(:text,"Copy").click
单击菜单项,但使用 watir-webdriver (0.2.3) 时报告找不到 LI 元素。虽然我可以通过使用 :class 找到包含 DIV 和 LI 的实例。
我在下面附上了一个菜单 HTML 的示例,有人可以建议一种可靠的方法来定位 LI 项目吗?
<div class="ws-menu-container ws-context-menu ws-context-menu-hidden" style="top: 16px; left: 214px; " id="Attributes-menu">
<ul class="ws-context-menu"><li class="ws-context-menu-disable"> Copy </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu-disable"> Add... </li>
<li class="ws-context-menu-disable"> Remove... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu-disable"> Clear Translation Flag </li>
<li class="ws-context-menu-disable"> Copy from Master Language... </li>
<li class="ws-context-menu-disable"> Push to Child Languages... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Options... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Refresh </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Help </li></ul></div>
I am trying to locate and click on a jQuery menu element, the menu is defined as multiple UL elements containing a number of LI elements.
Using Firefox 3.6.17 on Mac 10.5, in standard WATIR I've used;
browser.li(:text,"Options...").click
or
browser.div(:id,"Attributes-menu").li(:text,"Copy").click
to click on the menu item but using watir-webdriver (0.2.3) it is reporting the LI element cannot be found. Although I can find the containing DIV and an instance of LI by using :class.
I've attached an example of a menu HTML below, can anyone suggest a reliable method of locating the LI item?
<div class="ws-menu-container ws-context-menu ws-context-menu-hidden" style="top: 16px; left: 214px; " id="Attributes-menu">
<ul class="ws-context-menu"><li class="ws-context-menu-disable"> Copy </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu-disable"> Add... </li>
<li class="ws-context-menu-disable"> Remove... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu-disable"> Clear Translation Flag </li>
<li class="ws-context-menu-disable"> Copy from Master Language... </li>
<li class="ws-context-menu-disable"> Push to Child Languages... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Options... </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Refresh </li></ul>
<hr class="ws-context-menu-separator">
<ul class="ws-context-menu">
<li class="ws-context-menu"> Help </li></ul></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
This worked for me:
没有找到的原因是 nbsp; 的。除了 Željko 的正则表达式解决方案之外,您还应该能够通过将不间断空格的 Unicode 字节添加到您要查找的字符串中来实现此目的,例如:
The reason it's not found is the nbsp;'s. In addition to Željko's regexp solution, you should be able to do this by adding the Unicode bytes for a non-breaking space to the string you're looking for, e.g:
要执行 Zeljko 的解决方案但使用字符串变量,您需要从字符串变量创建正则表达式类的新实例,
有关详细信息,请参阅 Ruby Regexp 类的 Rdoc
To do Zeljko's solution but using a string variable you need to create a new instance of the regular expression class from your string variable
for more info see the Rdoc for the Ruby Regexp class