ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to mouse hover on a web element using WebDriver?

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

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!