Select Page

Category Selected: Automation Testing

187 results Found


People also read

Software Tetsing

QA vs QE: Understanding the Evolving Roles

Software Tetsing

Test Driven Development in Agile Framework

Automation Testing

Playwright Codegen: Record Tests in Seconds

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility
WebDriver Mouse Hover

WebDriver Mouse Hover

This is our very first article in Selenium, we hope it is helpful for Selenium users. Keep visiting Codoid blogs for more articles in the near future.

Using Custom JavaScript Mouse-event

//The below JavaScript code creates, initializes and dispatches mouse event to an object on fly.
String strJavaScript = "var element = arguments[0];"
            + "var mouseEventObj = document.createEvent('MouseEvents');"
            + "mouseEventObj.initEvent( 'mouseover', true, true );"
            + "element.dispatchEvent(mouseEventObj);";
	
//Then JavascriptExecutor class is used to execute the script to trigger the dispatched event.
((JavascriptExecutor) driver).executeScript(strJavaScript, element);
  

 

Using Device

//Getting mouse from driver object
Mouse mouse =((HasInputDevices)driver).getMouse();
	
//Invokes mouseMove method by passing element coordinates as argument
mouse.mouseMove(((Locatable)element).getCoordinates());
  

 

Using Advanced User Interactions API

Actions builder = new Actions(driver);

builder.moveToElement(element).perform();
//Note:  (Preferable for Firefox and HTMLUnit drivers)