Selenium2 中的 FirefoxDriver 是否有经过验证的 mouseOver 解决方法? [英] Is there a proved mouseOver workaround for FirefoxDriver in Selenium2?

查看:23
本文介绍了Selenium2 中的 FirefoxDriver 是否有经过验证的 mouseOver 解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Selenium Java 2.0b3.我有这个代码:

I'm using Selenium Java 2.0b3. I have this code:

...
WebDriver driver = new InternetExplorerDriver();
Selenium seleniumDriver = new WebDriverBackedSelenium(driver, "http://localhost:8088/Sistema/");
...
...
RenderedWebElement menuRegistrar = (RenderedWebElement)driver.findElement(By.xpath("//a[normalize-space()='Registrar']"));
seleniumDriver.mouseOver("//a[normalize-space()='Registrar']"); //makes element visible     
menuRegistrar.click();
seleniumDriver.mouseOut("//a[normalize-space()='Registrar']");
...

与 InternetExplorerDriver(带有 IE 8)一起工作就像一个魅力,但它不适用于 FirefoxDriver(带有 Firefox 4).我已经用代码尝试了很多东西,但没有任何效果.而且我必须使用 FirefoxDriver,因为我正在测试的应用程序在 IE 下表现不佳.

Works like a charm with InternetExplorerDriver (with IE 8), but it doesn't with the FirefoxDriver (with Firefox 4). I've tried a lot of things with the code and nothing works. And I must use the FirefoxDriver because the application I'm testing doesn't behave well with IE.

正如您可能猜到的,在 mouseOver 事件触发之前,Registrar"链接是隐藏的.

As you might guess, the "Registrar" link is hidden until the mouseOver event triggers.

任何经过验证的解决方法?感谢您的时间...

Any proved workarounds? Thanks for your time...

编辑:还尝试了 ChromeDriver 和 Chrome 11.也没有用.如果有适用于 Chrome 的解决方法,我会接受!

EDIT: also tried ChromeDriver with Chrome 11. Didn't work either. If there's a workaround that works with Chrome I'll take it!

ANSWER(使用 Selenium Java 2.0RC1、Windows 7、Firefox 4 的工作代码):感谢 Andy Tinkham 和 Luke Inman-Semerau:

ANSWER (WORKING CODE with Selenium Java 2.0RC1, Windows 7, Firefox 4): Thanks to Andy Tinkham and Luke Inman-Semerau:

//get the element that shows menu with the mouseOver event
WebElement menu = driver.findElement(By.xpath("//div[@id='nav']/li[3]"));

//the element that I want to click (hidden)
WebElement menuOption = driver.findElement(By.xpath("//a[normalize-space()='Registrar']"));

//build and perform the mouseOver with Advanced User Interactions API
Actions builder = new Actions(driver);    
builder.moveToElement(menu).build().perform();

//then click when menu option is visible
menuOption.click();

注意:高级用户交互 API 在浏览器上使用 NativeEvents(不支持跨平台).因此,如果您更改操作系统,此代码可能不会像那样工作.这就是我添加操作系统和浏览器详细信息的原因.请参阅 selenium 用户组中的问题

NOTE: The Advanced User Interaction API uses NativeEvents on the browsers (which is not supported cross platform). So this code might not work just like that if you change the OS. That's why I added the OS and browser detail. See question in selenium users group

推荐答案

我建议尝试 昨天在 2.0rc1 版本中添加的高级用户操作 API,因为看起来您仍在使用 Selenium 1 API(通过 WebDriverBackedSelenium),我不确定 Firefox 4 支持多少提供.我没有将 Java 用于 Selenium 测试,但在我看来,您想要做的事情是这样的:

I would suggest trying the Advanced User Actions API that was added in the 2.0rc1 release yesterday, as it looks like you're using the Selenium 1 API still (going through WebDriverBackedSelenium), and I'm not sure how much Firefox 4 support that provides. I'm not using Java for my Selenium tests, but it looks to me like what you would want to do is something like this:

   Actions builder = new Actions(driver); // Or maybe seleniumDriver? Not sure which one to use

   Actions hoverOverRegistrar = builder.moveToElement(menuRegistrar);

   hoverOverRegistrar.perform();

这篇关于Selenium2 中的 FirefoxDriver 是否有经过验证的 mouseOver 解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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