当前位置: 首页 > 面试题库 >

Selenium2中的FirefoxDriver是否有经过验证的mouseOver解决方法?

贡建修
2023-03-14
问题内容

我正在使用 Selenium Java 2.0b3 。我有这个代码:

...
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中表现不佳。

您可能会猜到,“ Registrar”链接将被隐藏,直到mouseOver事件触发。

任何可行的解决方法?谢谢你的时间…

编辑 :也尝试过将ChromeDriver与Chrome 11配合使用。如果有适用于Chrome的解决方法,我会采取的!

解答(与Selenium Java 2.0RC1,Windows 7,Firefox 4协同工作的代码) :感谢Andy Tinkham和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(跨平台不支持)。因此,如果您更改操作系统,则此代码可能无法正常工作。这就是为什么我添加了操作系统和浏览器详细信息的原因。在硒用户组中查看问题


问题答案:

我建议尝试使用昨天在2.0rc1版本中添加的Advanced
User Actions
API
,因为您似乎仍在使用Selenium
1 API(通过WebDriverBackedSelenium),并且我不确定Firefox
4是否支持该功能。提供。我没有在Selenium测试中使用Java,但是在我看来,您想要做的事情是这样的:

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

   Actions hoverOverRegistrar = builder.moveToElement(menuRegistrar);

   hoverOverRegistrar.perform();


 类似资料:
  • 本文向大家介绍CKEditor无法验证的解决方案(js验证+jQuery Validate验证),包括了CKEditor无法验证的解决方案(js验证+jQuery Validate验证)的使用技巧和注意事项,需要的朋友参考一下 最近项目的前端使用了jQuery,表单的前端验证用的是jQuery Validate,用起来很简单方便,一直都很满意的。 前段时间,根据需求为表单中的 textarea 类

  • 浏览AssertJ的API时,我似乎没有发现任何涉及Mockito行为的内容。验证现在我的断言都使用AssertJ fluent API,还有Mockito。验证哪一种是破坏断言流的。 有没有类似的方法来验证我错过的AssertJ中的方法没有被调用、只被调用一次等?

  • 我试图在提供者端运行一个PACT测试,但我不知道如何操作从PACT文件中获得的请求体。我需要这样做,因为我必须使用来自State Step的id。 此外,更复杂的是,我的主体是一个XML。下面是我的协议请求的样子: 正如我所说的,在Provider状态下,我将有一个请求,并且这个请求的响应将是让我们说'Mary'。所以我的问题是,在执行验证测试时,如何将协议请求体中的“Jane”替换为“Mary”

  • 我看到几乎每个人都在使用语句这里我们创建了一个类的实例,其类型为;如果我直接创建一个FirefoxDriver实例,作为

  • 问题内容: 我需要进行以下测试,以验证是否已调用Person类的所有getter。到目前为止,我已经使用了Mockito的verify()来确保每个getter都被调用。有没有办法通过反思做到这一点?可能是将新的吸气剂添加到Person类的情况,但是测试会错过这一点。 问题答案: 通常,不要嘲笑被测类。如果您的测试是针对Person的,则您永远都不会看到它,因为这很明显地表明您正在测试模拟框架而不