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)
Comments(0)