Mouse Hover in Selenium

This is widely known testing scenarios to perform mouse hover in Selenium. You can see many scenarios in our testing where you needed to perform mouse hover to see the calendar, email schedule etc.

 

To handle the mouse events and mouse hover using selenium WebDriver. We can use advanced user interactions API constructor “Actions” with “moveToElement” method.

We will see, How we can perform the mouse events and mouse hover in selenium.

 

Suppose we have a scenario. Where we have to hover the mouse on the menu and then sub list will open. Now we need to click the item from that sublist.

For this, you need actions object. You should first move the menu title, and then move to the sub menu item and click it.

 

Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

For example, We will open the Times Of India website and hover the mouse on menu element ‘World’ and then click on the subelement ‘Europe’.

Below is the sample code to perform Mouse Hover action –

Mouse Hover inn Selenium

 

The above code will open the Times of India website. Hover the mouse on ‘World’ web element and then click on the submenu ‘Europe’.

You can try the above code on your local or generate the new code for your testing using the reference of above code.

 

So this is the way how we can perform the mouse hover and perform the action on sub elements. Sometimes you need to verify the hover text or hover calendar.

For this you can hover on web Element and perform getText() and isElementVisible() methods for your testing.

0 Comment

Leave a Reply