在 Watir 中链接元素时如何让点击事件起作用?
我正在尝试在 Watir 中为我们的 Web 应用程序设置一些 UI 测试。我在传播点击事件时遇到了麻烦。我们使用 EXTJS 来制作选项卡,这些选项卡是生成的 html 中的跨度。
如果我选择这样的跨度,它会起作用:
span1 = @browswer.span(:text=>"Tab Name")
span1.click
问题是当我有一个具有相同名称的子选项卡并且希望能够区分它们时。我发现显式选择子选项卡的唯一方法是首先选择子选项卡所在的列表,然后从中选择子选项卡。
ul = @browser.ul(:class=>/tab-strip-bottom/)
span2 = ul.span(:text=>"Tab Name")
span2.click
span2.click 似乎没有执行任何操作。 span1 和 span2 之间唯一的不同(我可以看到)是容器属性。 span1.@container = @browser,span2.@container = ul。
我尝试在 span2 上设置容器
span2.instance_variable_set("@container", @browser)
,但最终我还是点击了错误的选项卡。对此有什么想法吗? 谢谢!
I am attempting to set up some UI testing in Watir for our web application. I'm running into trouble getting the click events to propagate. We are using EXTJS to make tabs, which are spans in the resulting html.
If I select a span like this it works:
span1 = @browswer.span(:text=>"Tab Name")
span1.click
The trouble is when I have a subtab with the same name and want to be able to differentiate them. The only way I've found to select the subtab explicitly is to first select the list that the subtab is in, and then select the subtab from that.
ul = @browser.ul(:class=>/tab-strip-bottom/)
span2 = ul.span(:text=>"Tab Name")
span2.click
span2.click doesn't appear to do anything. The only different (I can see) between span1 and span2 is the container attribute. span1.@container = @browser, span2.@container = ul.
I tried setting the container on span2 with
span2.instance_variable_set("@container", @browser)
but then I wind up clicking on the wrong tab anyway. Any thoughts on this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请分享HTML代码,我什至不明白这个问题。
也许您需要触发一些 JavaScript 事件。请参阅如何找出触发了哪些 JavaScript 事件?
Please share the HTML code, I do not even understand the problem.
Maybe you need to fire some JavaScript event. See How to find out which JavaScript events fired?
我终于解决了 xpath 遇到的问题。
这并不理想,因为 xpath 代码非常难看。如果可以使用 watir 的“candy”选择器来选择元素,那么可维护性会更好。
I finally solved the problem I was having with xpath.
It isn't ideal because the xpath code is pretty ugly. If it's possible to select the element by using watir's "candy" selectors, that would be much better for maintainability.
我们有一个多层的网页菜单,听起来像你所拥有的。鼠标将在进入下一个选择(直接对角线)时离开第二级菜单,并且第二级菜单将关闭。这就是你所说的吗?我们通过触发 javascript 解决了这个问题,因为菜单项调用了 javascript(Zeljko 的解决方案)。我们只需要记下菜单项的 ID 即可。不确定这是否比 xpath 解决方案更丑或更漂亮。我说“我们”是因为我需要这方面的帮助。
We had a web page menu with multiple tiers, sounds like what you have. The mouse would drop off the second level of the menu while going to the next selection (directly diagonal) and the second menu level would close. Is that what you are talking about? We solved it by firing javascript because the menu items called javascript (Zeljko's solution). We just needed to note the id's of the menu items. Not sure if that is uglier or prettier than the xpath solution. I say "we" because I needed help with that.
当有多个匹配对象时,您可以指定要使用的索引。这对你有用吗?
索引值与您正在搜索的容器相关。有关搜索对象时使用的所有可能性的表格,请参阅:Watir 支持的 HTML 元素
You can specify an index to use when there are multiple matching objects. Does this work for you?
The index values are relative to the container you're searching in. For a table of all possibilities to use when searching for objects see: HTML Elements Supported By Watir