How to do mouse hover using Selenium WebDriver in Firefox 19?

Mathew M Visacanthara picture Mathew M Visacanthara · Mar 11, 2013 · Viewed 57.8k times · Source

I have used selenium 2.31.

I have used Actions class for mouse movement. Using this I moved the mouse over a menu and its submenu appeared only for a fraction of second unlike with older version of Firefox .

Because of this issue I cannot select the sub menu using driver.findElement as it throws an exception "element cannot be scrolled into view".

Is there any solution for this?

Answer

SerkanC picture SerkanC · Mar 11, 2013

With the actions object you should first move the menu title, and then move to the popup menu item and click it. Don't forget to call actions.perform() at the end. Here's some sample Java code:

Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText("Menu heading"));
actions.moveToElement(menuHoverLink);

WebElement subLink = driver.findElement(By.cssSelector("#headerMenu .subLink"));
actions.moveToElement(subLink);
actions.click();
actions.perform();