mootools,watir webdriver onmouseover无效 [英] mootools, watir webdriver onmouseover take no effect

查看:46
本文介绍了mootools,watir webdriver onmouseover无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试表明,当页面具有mootools lib时,webdriver fire_event("onmouseover")无效. 当删除mootools lib时,fire_event("onmouseover")生效. 如何获得解决方法?

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页面如下:

<!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">
                        &nbsp;|&nbsp;<a class="unline">edit 1</a>
                        |&nbsp;<a class="unline">delete</a>
                </div>
           </div>                                                
    </div>
</body>
</html>

watir正在关注:

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

推荐答案

我倾向于向mootools的人问这个问题,我想这是在某种程度上拦截了事件,因此浏览器元素永远不会真正看到"当您发射它时,但这只是一个猜测.

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.

他们的工具也可能会添加其他类型的CSS逻辑或其他控制此项目是隐藏还是可见的东西,我已经看到很多使用元素类型和类以及元素组合的规则:悬停psuedoclass来实现菜单

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

对于仅使用CSS来控制元素可见性的控件,我还无法找到一种方法(尚未)导致在浏览器级别识别出悬浮"状态,因此CSS:hover规则会采用效果并导致菜单元素出现.

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.

解决方案可能是通过本质上执行将通过onmouseover触发的相同脚本代码并查看是否使元素显示来强制更改元素的可见性.

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.

browser.execute_script("document.getElementById('id6').style.display='block';")

如果这不起作用,则可以通过临时更改特定的样式控件来在CSS级别上进行操作.我已经通过Jquery(因为我们的应用已经使用它)使用了这种通用格式

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

browser.execute_script("jQuery('CSS-Rule-Name').css({display: 'block'});")

在我的特殊情况下,暴露所有下拉菜单的代码最终看起来像这样

In my particular case the code to expose all the pulldown menus ends up looking like this

browser.execute_script("jQuery('.navigation #secondary_nav > li ul.tertiary_nav').css({display: 'block'});")

这当然必须适应您的代码,因为CSS规则可能会有所不同.我发现规则的方法是使用开发人员工具,在dom中选择菜单的容器元素,然后选择跟踪样式"并展开"display"属性,该属性应为您提供特定的CSS规则(在我的情况下,是.navigation #secondary_nav > li ul.tertiary_nav),它控制元素的显示(通常是无"或块"). (还会添加添加:hover的其他类似规则,这些规则将在浏览器确定鼠标悬停在适用元素上时生效)

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 )

这有点麻烦,但是可以完成所需的工作,这使菜单项可见,因此您可以在其上使用诸如.click方法之类的东西.

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'

这篇关于mootools,watir webdriver onmouseover无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆