Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 340
Mathew M Visacanthara Avatar asked Mar 11 '13 13:03

Mathew M Visacanthara


People also ask

Which is the command to perform mouse hover in Selenium?

We can perform mouseover action on elements in Selenium with the help of Actions class. In order to perform the mouse movement we will use moveToElement () method of the Actions class. Finally use build(). perform() to execute all the steps.

Which class can be used for mouse hover?

You can use the Action class to perform the mouse movement like hover, navigate, moveToElement, and Keyboard events like click, click and hold and Doubleclick extra.

Which of the following in Selenium is used to mouse hover through JavaScriptExecutor?

We can use Actions class to perform mouse hovers, if we are are not able to perform due to any restrictions, we can use JavaScriptExecutor to perform the same action. Below is the example to do mouse hover using JavaScriptExecutor. You need to wait for the Element to be disabled and then try to perform mouse hover.


1 Answers

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();
like image 166
SerkanC Avatar answered Oct 06 '22 01:10

SerkanC