How to perform mouse hover action using Selenium Wedriver
This post is part of the Selenium Webdriver Commands series. We usually come across some scenarios in automation of mouse hover. It's quiet a tricky thing to perform in automation. Thanks to the Actions Class/commands in Selenium Webdriver. We already have a Selenium command for it.
Below is the code for Mouse hover in Selenium Webdriver:
Explanation of above code:
- Creating object of Actions class as actions. And passing driver object to constructor of Actions class.
- In second line, creating an Object of WebElement and passing Xpath locator to it.
- moveToElement() is the method/command to perform mouse hover.
- actions.build().perform(); - This code is mandatory to finish any actions class command. build() method combines multiple actions into one single action and perform() executes those multiple actions as one action.
For list of Selenium tutorials click here: Selenium Webdriver Tutorials Series
Top Posts -
Join Telegram channel of this blog at https://t.me/techlisticspace
Feel free to ask queries or share your thoughts in comments or email me.