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

查看:134
本文介绍了在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事件触发。

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

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

Any proved workarounds? Thanks for your time...

编辑:还尝试使用Chrome 11驱动ChromeDriver。也没有用。如果有适用于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!

答案(使用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

推荐答案

我建议您尝试高级用户操作API ,因为看起来你仍在使用Selenium 1 API(通过WebDriverBackedSelenium),我不知道Firefox 4有多少提供的支持。我没有在我的Selenium测试中使用Java,但在我看来,你想做的事情是这样的:

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天全站免登陆