Interview Questions

Selenium WebDriver - How to mouse hover on a web element using WebDriver?

Selenium WebDriver Interview question and Answers


(Continued from previous question...)

Selenium WebDriver - How to mouse hover on a web element using WebDriver?

WebDriver offers a wide range of interaction utilities that the user can exploit 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.

Sample Code:
1 // Instantiating Action Interface
2 Actions actions=new Actions(driver);
3 // howering on the dropdown
4 actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
5 // Clicking on one of the items in the list options
6 WebElement subLinkOption=driver.findElement(By.id("id of the sub link"));
7 subLinkOption.click();

(Continued on next question...)

Other Interview Questions