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?
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.
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.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With