程序在打开弹出窗口后卡住了 [英] Program stuck after opening a popup

查看:164
本文介绍了程序在打开弹出窗口后卡住了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于程序在打开弹出窗口后卡住了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆