Program gets stuck after opening popup with selenium webdriver

The tool clicks a button and a modal window appears (where I need to fill in some information and then go to the parent window). But as soon as a new modal appears, my code stops. The code resumes after I manually close the new popup.

Since the code itself stops, I cannot perform any action on the new popup or parent window.

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

      

In the above code, Up is printed to the console and Down is not printed until I manually close the popup.

+1


source to share


3 answers


Finally, a decision after spending many days.

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



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

      

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

0


source


 driver.switchTo().alert();

      

write this line of code after clicking on the control button, there will be a radio button for the popup and then write



alert.accept();

      

the alert will be closed

+2


source


you need to transfer control to your popup first before doing any operation on the popup: -

to move selenium control in popup: -

 driver.switchTo().alert();

      

Now you can perform your action in the pop-up window.

To send your control back to the main window use below code: -

driver.switchTo().defaultContent();

      

Hope this helps you :)

+1


source







All Articles