Wednesday, July 20, 2011

How to do doubleClick on WebElement , WindowMaxmize Using Webdriver

 To maximize the active Window :

public void windowMaximize() {
((JavascriptExecutor) driver).executeScript("if (window.screen){window.moveTo(0, 0);window.resizeTo(window.screen.availWidth,window.screen.availHeight);};");
}

To DoubleClick an Element

public void doubleClick(WebElement webElement) {
//For FF browser.
((JavascriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');"
+ "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);"
+ "arguments[0].dispatchEvent(evt);",webElement);

//For IE
//((JavascriptExecutor)driver).executeScript("arguments[0].fireEvent('ondblclick');", webElement);
}

1 comment:

Anonymous said...

Thanks a lot! It saved my day.