mootools、watir webdriver onmouseover 不起作用
我的测试表明,当页面具有 mootools lib 时,webdriver fire_event("onmouseover") 不起作用。 当删除mootools lib时,fire_event("onmouseover")生效。 我怎样才能找到解决方法?
html 页面如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type='text/javascript' src='http://demos111.mootools.net/demos/mootools.svn.js'></script></head>
<body>
<div onmouseover="document.getElementById('id6').style.display='block';"
onmouseout="document.getElementById('id6').style.display='none';"
style="overflow:hidden;" id="id61" class="trbgcolor0">
<div style="height: 18px;">
<div style="float: left; ">
<b>plan category 2682</b>
<a class="unline"> add 1</a>
</div>
<div style="display: none;" id="id6">
| <a class="unline">edit 1</a>
| <a class="unline">delete</a>
</div>
</div>
</div>
</body>
</html>
watir 如下:
require "rubygems"
require "watir-webdriver"
require 'test/unit'
class TC_article_example < Test::Unit::TestCase
def test_search
browser = Watir::Browser.new :firefox
browser.goto("http://192.168.88.120/mgt/login/t2.html")
sleep 1
oo = browser.div(:id=>"id61")
oo.fire_event "onmouseover"
puts "2 001 "
end
end
My test shows that webdriver fire_event("onmouseover") takes no effect when page has mootools lib.
when remove mootools lib, fire_event("onmouseover") takes effect.
how can I get a workaround?
html page is following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type='text/javascript' src='http://demos111.mootools.net/demos/mootools.svn.js'></script></head>
<body>
<div onmouseover="document.getElementById('id6').style.display='block';"
onmouseout="document.getElementById('id6').style.display='none';"
style="overflow:hidden;" id="id61" class="trbgcolor0">
<div style="height: 18px;">
<div style="float: left; ">
<b>plan category 2682</b>
<a class="unline"> add 1</a>
</div>
<div style="display: none;" id="id6">
| <a class="unline">edit 1</a>
| <a class="unline">delete</a>
</div>
</div>
</div>
</body>
</html>
watir is following:
require "rubygems"
require "watir-webdriver"
require 'test/unit'
class TC_article_example < Test::Unit::TestCase
def test_search
browser = Watir::Browser.new :firefox
browser.goto("http://192.168.88.120/mgt/login/t2.html")
sleep 1
oo = browser.div(:id=>"id61")
oo.fire_event "onmouseover"
puts "2 001 "
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我倾向于向 mootools 人员询问这一点,我猜想它以某种方式拦截了事件,因此当您触发它时,浏览器元素永远不会真正“看到”它,但这只是一个猜测。
他们的工具还可能添加一些其他类型的 CSS 逻辑或其他内容来控制该项目是隐藏还是可见,我已经看到很多规则使用元素类型和类的组合以及 :hover psuedoclass 来实现菜单
对于专门使用 CSS 来控制元素可见性的控件,我还没有找到一种方法来导致在浏览器级别识别的“悬停”状态,以便 CSS :hover 规则生效并导致菜单要出现的元素。
解决方案可能是通过本质上执行通过 onmouseover 触发的相同脚本代码来强制更改元素的可见性,并查看是否使元素显示出来。
如果这不起作用,您也许可以通过临时更改特定样式控件来在 CSS 级别进行操作。我已经通过 Jquery (因为我们的应用程序已经使用它)使用这种通用格式完成了此操作
在我的特殊情况下,公开所有下拉菜单的代码最终看起来像这样
当然,这必须适应您的代码,因为CSS 规则可能会有所不同。我找到规则的方法是使用开发人员工具,在 dom 中选择菜单的容器元素,然后选择“跟踪样式”并展开“显示”属性,该属性应该为您提供特定的 CSS 规则(在我的例子中是是
.navigation #secondary_nav > li ul.tertiary_nav
) 控制元素的显示(通常为“none”或“block”)。 (还有其他类似的规则,添加了:hover
,当浏览器确定鼠标悬停在适用的元素上时生效)它有点混乱,但它做了需要的事情,这使得菜单项可见,以便您可以在其上使用诸如
.click
方法之类的东西。如果该操作不会导致页面刷新,您可以使用相同的脚本再次隐藏菜单,但将其设置为“无”而不是“阻止”
I'd be inclined to ask the mootools folks about this, offhand I'd guess it's somehow intercepting the event, so the browser element never really "see's" it when you fire it, but that's just a guess.
Their tools might also be adding some other kind of CSS logic or something else that governs if this item is hidden or visible, I've seen that a lot with rules that use a combination of element type and class along with the :hover psuedoclass to implement menus
For controls that use exclusively CSS to control the element visibility, I've not been able to find a way (yet) to cause a 'hover' state that is recognized at the browser level such that the CSS :hover rules take effect and cause the menu element(s) to appear.
The solution may be to force a change in the element's visibility by essentially executing the same script code that would fire via onmouseover and see if that makes the element show up.
If that does not work, you might be able to manipulate things at the CSS level by temporarily altering the particular style control. I've done this via Jquery (since our app already uses it) using this general format
In my particular case the code to expose all the pulldown menus ends up looking like this
That would have to be adapted to your code of course, as the CSS rule will likely be different. The way I found the rule is to use the developer tools, select the container element for the menu in the dom, then chose 'trace styles' and expand the 'display' property which should give you the specific CSS rule (in my case it is
.navigation #secondary_nav > li ul.tertiary_nav
) that is controlling the display (usually 'none' or 'block') of the element. (there will be other similar rules with:hover
added that take effect when the browser determines that the mouse is hovering over the applicable element )Its a tiny bit of a kludge, but it does what is needed, which is make the menu item visible so you can then use things like the
.click
method on them.If that action does not cause a page refresh, you can hide the menu again using the same script but setting it to 'none' instead of 'block'
解决方法是:browser.execute_script("abc(true)")
a workaound is :browser.execute_script("abc(true)")