Selenium 和 :hover css

2023-11-01前端开发问题
2

本文介绍了Selenium 和 :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.

Google 显示我并不孤单,但还没有解决方案.有些人评论说您必须添加一些 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')]"));

很遗憾,moveHover() 方法尚不存在.

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();

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

The End

相关推荐

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

这种自调用匿名函数变体背后的原因
Reason behind this self invoking anonymous function variant(这种自调用匿名函数变体背后的原因)...
2024-04-20 前端开发问题
4

缩放背景图像以适合 ie8 窗口
Scale background image to fit ie8 window(缩放背景图像以适合 ie8 窗口)...
2024-04-19 前端开发问题
11

IE7 (IETEster) 中的@fontface 无法正常工作
@fontface in IE7 (IETEster) not working properly(IE7 (IETEster) 中的@fontface 无法正常工作)...
2024-04-19 前端开发问题
9