Saturday, November 17, 2012

window.showModalDialog - Webdriver Issue

Last month I was automating a scenario where the popup window showsup with Yes/No button. While verifying manually i thought it can be handled either by using Alert / selectWindow and perform actions.
At first I tried to record the same scenario using Selenium-IDE
Unfortunately IDE is not able to recognize the window :(.

So I thought to verify how the popup window was actually called/invoked.
- On click a button , it popups the child window and the main window is still waiting to complete its transcation.
-  Webdriver's driver will be waiting for its turn to complete the transcation , and not able to execute the statements until i close the popup manually. (In IE with selectWindow.. worked , but in Firefox ..NO).
-I verified the button using firebug , and the html code was something like <... onclick="return mypopup('Click Yes if you need to continue')"....>
-And in the mypopup javascript code is using window.shwoModalDialog
-For me I need to click Yes , and the application is actually returning true. if No, returns false.

So finally I written a piece of code which updates the the HTML code in the app at run time using.

public void clickElementAndConfirmPopup(){
WebElement element =  ..findElement.....
((JavascriptExecutor) DriverFactory.getDriver()).executeScript(
"arguments[0].setAttribute('onclick',arguments[1]);", element, "return true");
element.click(); } public void clickElementAndConfirmPopup(){

WebElement element = ..findElement.....
((JavascriptExecutor) DriverFactory.getDriver()).executeScript(
"arguments[0].setAttribute('onclick',arguments[1]);", element, "return false");
element.click();
}

- And now able to handle in both browsers (IE and FireFox)..



No comments: