4

I have a simple CSS-based dropdown menu, and I'm trying to click on one of the menu items in a Java Selenium (WebDriver) test.

enter image description here

Both the menu (<ul> element) and the items (<a>) have IDs and creating corresponding WebElement objects works fine. I'm trying to click on one of the items with code like:

   hoverOver(transfersMenu);
   transferLink.click();

In hoverOver(), I've tried all three answers from this question, but none of them work. I keep getting:

org.openqa.selenium.ElementNotVisibleException: 
    Element is not currently visible and so may not be interacted with 
Command duration or timeout: 2.06 seconds

(I've tried calling transferLink.click() also before hoverOver(), in the hope that the implicit wait would make it work, but nope.)

Any idea how to make the hovering work so that the link can be clicked?

Selenium version 2.21.0. I'm running the tests on Linux (Ubuntu), using Firefox 13.0. A colleague just tried on Windows (using Firefox 12.0), and it didn't work for him either.

Update: As per Slanec's tip in comments, and these instructions, I tried setEnableNativeEvents(true) on the FirefoxProfile. At first this failed:

org.openqa.selenium.InvalidElementStateException: 
    Cannot perform native interaction: Could not load native events component.

...but after I upgraded to Selenium 2.23.1, I no longer get that complaint.

Still, the hovering doesn't work (with native events on or off). :-/

4

3 回答 3

0

你如何运行你的测试类?我发现通过 ANT 运行 WebDriver 使悬停操作变得不可能,而从命令行 (TestNG JAR) 或从 Eclipse 运行测试类就可以了。

于 2014-06-10T10:34:13.963 回答
0

在单击链接之前,我使用以下代码将鼠标悬停在我们的菜单上 1 秒钟,就像您正在使用的那样:

action = new SeleniumActionHelper(driver);

WebElement currentUser = findElementByLinkText("testing1");
action.mouseHover(currentUser);
Thread.sleep(1000);

值得注意的是,鼠标光标需要保留在浏览器窗口中才能保持悬停。如果鼠标光标在浏览器窗口之外,我会体验到菜单的快速闪烁,但它不会保持可见

于 2012-06-20T21:25:16.200 回答
0

试试这个例子:

WebElement menuHoverLink= driver.findElement(By.id("test"));
actions.moveToElement(menuHoverLink).perform();
driver.findElement(By.id("test")).click();
Thread.sleep(6000); 
于 2013-12-04T06:12:57.623 回答