How to mouse hover on a web element using WebDriver?
Now a days mouse hover functionality is used by most of the developers in web application development. So it is very much important to automate this functionality too without which testing is incomplete.
WebDriver offers a wide range of interaction utilities that the user can use to automate mouse and keyboard events. Action Interface is one such utility which simulates the single user interactions.
Thus, In the following scenario, we have used Action Interface to mouse hover on a drop down which then opens a list of options.
- // Instantiating Action Interface
- Actions actions=new Actions(driver);
- // howering on the dropdown
- actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
- // Clicking on one of the items in the list options
- WebElement subLinkOption=driver.findElement(By.id("id of the sub link"));