rsaha77 rsaha77 - 2 months ago 13
Java Question

Program stuck after opening a pop up using selenium webdriver

The tool clicks a button and a modal window appears (where I need to fill in some information and later move to parent window). But as soon as the new modal window appears, my code stops. The code resumes once I manually close the new pop up window.

Since the code itself halts, I am not able to perform any actions in the new pop up window, nor in the parent window.

System.out.println ("Up");
WebElement addButton = driver.findElement(By.id("btnAdd"));
addButton.click ();
System.out.println ("Down");


In the above code, Up gets printed in the console while Down doesn't get printed until I manually close the pop up window.

Answer

Finally a solution after wasting a lot of days.

The only way is to not use showModalDialog. This can be done by adding the folowing before the .click() :

((JavascriptExecutor) driver).executeScript("window.showModalDialog = window.open;");

which will call window.open instead of window.showModalDialog.

Comments