您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Java或Javascript中的窗口对话框和弹出窗口处理

Java或Javascript中的窗口对话框和弹出窗口处理

我使用硒1,它可以很好地处理我的应用程序中的弹出窗口。

    //Click on browse file button, open a popup
    selenium.click("//input[@value='Browse...']");

    //waiting for popup to load
    selenium.waitForPopUp("_Dialog", "30000");

    //selecting the popup by passing window name
    selenium.selectWindow("name=_Dialog");

    //click a link inside pop up window
    selenium.click("link=something");

    //Put other popup operations here

    //click cancel button for pop up
    selenium.click("cancel");

    //back to main window
    selenium.selectwindow("null")

要从警报框中获取消息,请使用selenium.getAlert();。这将以字符串形式返回包含在警报框中的消息。

另外,有时需要在切换到警报之前检查是否已发生警报。

        int noofWindows = selenium.getAllWindowNames().length;
        if (noofWindows > 1){
        //selects the second window 
        selenium.selectWindow(selenium.getAllWindowIds()[2]);
        //Prints the message in the alert window
        System.out.println(selenium.getAlert());
        }

如果不需要在IE中运行测试,请在执行代码之前使用firefox(* chrome)并关闭所有其他窗口。

我希望这可以帮助你。

*所有提及的代码均用于处理JavaScript弹出窗口。我不确定这是否适用于Vb脚本。

我认为IE下载弹出窗口是Windows事件,因此无法直接由Selenium处理,因此您必须使用Java AWT或AutoIT。

AutoIT脚本应该类似于

WinWaitActive(windowTitle)
ControlClick(windowTitle,"",buttonName)

并将其另存为IEsave.exe。注意:我没有尝试过此AutoIT脚本。

现在,您已从程序中执行IEsave.exe。我在这里使用Java。

java.lang.Runtime.getRuntime().exec("c:/IEsave.exe");

这将执行该文件,该文件将依次处理Windows的保存按钮事件。

您可以创建类似的exe文件来处理其他窗口的事件。

希望这能解决您的问题。

javascript 2022/1/1 18:25:13 有344人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶