硒和:hover css [英] Selenium and :hover css

查看:168
本文介绍了硒和:hover css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用selenium-rc和java客户端,我想测试一个菜单,当用户在其上移动鼠标时,该菜单打开。当鼠标离开菜单时关闭。这是使用:hover css,没有任何javascript。

Using selenium-rc and the java client, I want to test a menu which opens when the user moves the mouse over it. It closes when the mouse leaves the menu. This is done using :hover css, without any javascript.

在selenium中,鼠标操作有很多方法,但是没有一个方法可以触发任何css :hover

In selenium, there are many methods for mouse actions, but none of them seems to trigger any css :hover style to be used.

谷歌表明,我并不孤单的这个问题,但没有一个解决方案。有些人说你必须添加一些javascript代码;然而,在selenium rc,我不认为我甚至有一个适当的地方用户提供的额外的JavaScript代码。

Google shows that I am not alone with this problem, but there has not be a solution. Some folks comment that you had to add some javascript code; however, in selenium rc, I don't think that I even have a proper place for user-contributed additional javascript code.

我的愿望将是下面的代码工作,因为div#navi_settings包含一个包含 - 通常是不可见的元素的菜单:

My wish would be the following code to work, given that a div#navi_settings contained the menu which contains the - normally invisible - a element:

selenium.mouseHover("css=div#navi_settings");
assertTrue(selenium.isVisible("//a[contains(text(), 'Text on link')]"));


$ b尚未存在。

Unfortunately, the method moveHover() does not yet exist.

推荐答案

我找不到一种方法来使用Selenium接口。但是,由于我使用Selenium 2,我可以使用WebDriver API,如 http://groups.google.com/group/selenium-developers/msg/8210537dde07155f?pli=1

I couldn't find a way to do this using the Selenium interface. However, since I am using Selenium 2, I can use the WebDriver API, as per http://groups.google.com/group/selenium-developers/msg/8210537dde07155f?pli=1

在您的情况下,像这样可以工作,如果你可以升级到Selenium 2:

In your case, something like this may work, if you can upgrade to Selenium 2:

WebDriver webDriver; 
...
((RenderedWebElement) webDriver.findElement(By.cssSelector("div#navi_settings"))).hover();

这篇关于硒和:hover css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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