Program stuck after opening a popup

删除回忆录丶 提交于 2019-12-11 09:54:02

问题


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 popup window.

Since the code itself halts, I am not able to perform any actions in the new popup 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 popup window.


回答1:


 driver.switchTo().alert();

write this line of code after clicking on button control will get switch to the pop up and then write

alert.accept();

alert will get close




回答2:


you need to move control to your pop-up window first before doing any operation on pop-up window:-

code to move selenium control on pop-up window:-

 driver.switchTo().alert();

Now you can perform you action on pop-up.

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

driver.switchTo().defaultContent();

Hope it will help you :)




回答3:


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.



来源:https://stackoverflow.com/questions/36324436/program-stuck-after-opening-a-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!