How to Mouse Hover on a Web Element Using WebDriver

0
16

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.

Sample Code:

  1. // Instantiating Action Interface
  2.  
  3. Actions actions=new Actions(driver);
  4.  
  5. // howering on the dropdown
  6.  
  7. actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
  8.  
  9. // Clicking on one of the items in the list options
  10. WebElement subLinkOption=driver.findElement(By.id("id of the sub link"));
  11.  
  12. subLinkOption.click();
Facebook Comments
(Visited 11 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here