Select Page

Category Selected: Automation Testing

163 results Found


People also read

Mobile App Testing

Appium Debugging: Common Techniques for Failed Tests

Artificial Intelligence

AI vs ML vs DL: A Comprehensive Comparison

Artificial Intelligence

ANN vs CNN vs RNN: Understanding the Difference

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)