Tuesday, March 4, 2014

Mouse Action using JS

Mouse Over and MouseOut

JavascriptExecutor executor = (JavascriptExecutor)DriverFactory.getDriver();
        executor.executeScript("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}", element);
                         executor.executeScript("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseout', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseout');}", element);

Mouse Click

 JavascriptExecutor executor = (JavascriptExecutor)DriverFactory.getDriver();
                executor.executeScript("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mousedown', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmousedown');}", element);
                executor.executeScript("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseup', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseup');}", element);
        }