程序在打开弹出窗口后卡住了

问题描述:

该工具单击一个按钮,然后出现一个模态窗口(我需要在其中填写一些信息,然后移至父窗口).但是,一旦出现新的模态窗口,我的代码就会停止.一旦我手动关闭新的弹出窗口,代码就会恢复.

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.

最后是浪费大量时间后的解决方案.

Finally a solution after wasting a lot of days.

唯一的方法不使用showModalDialog .这可以通过在.click()之前添加以下内容来完成:

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;");

它将调用window.open而不是window.showModalDialog.

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