窗口对话框Java 或 Javascript 中的弹出处理 [英] Window Dialogs & Popup handling in Java or Javascript

查看:16
本文介绍了窗口对话框Java 或 Javascript 中的弹出处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要操纵弹出窗口 &使用 Java 或基于 Javascript 的自动化解决方案.

I need to manipulate Popups & Download Dialogs of IE browser using either Java or Javascript based automated solution.

我尝试过使用 selenium2,但它无法正常工作,因此有任何其他建议.实际上 selenium2 不提供警报/下载对话框的正确处理,所以我正在考虑使用其他一些 javascript/java 解决方案.

I tried with selenium2 but its not working properly so any other suggestion for the same. Actually selenium2 does not provide proper handling of alert/download dialogs so I am thinking to use some other javascript/java solution.

使用下载对话框:我需要将下载的文件保存到特定位置.使用警报对话框:我需要检查显示的消息并单击特定按钮.

With Download Dialog: I need to save the downloaded file to particular location. With Alerts Dialogs: I need to check the displayed message and click on the particular button.

任何建议表示赞赏.谢谢.

Any suggestion is appreciated. Thanks.

推荐答案

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

I use selenium 1 and it works well to handle popups in my application.

    //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();.这会将警报框中包含的消息作为字符串返回.

To get the message from alert boxes, use selenium.getAlert();. This will return the message contained in the alert box as String.

此外,有时您需要检查,在切换到警报之前是否发生了警报.

Also, sometime you will need to check, whether alert has occurred before switching to it.

        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) 并关闭所有其他窗口.

If it is not a necessity to run test in IE, use firefox(*chrome) and close all other windows before executing the code.

希望对你有帮助.

*所有提到的代码都是为了处理 JavaScript 弹出窗口.我不确定这是否适用于 Vb 脚本.

*All the mentioned code is for handling JavaScript pop-ups. I'm not sure whether this will work for Vb-script or not.

编辑

我认为 IE 下载弹出窗口是一个 windows 事件,因此 selenium 无法直接处理,为此您必须使用 Java AWT 或 AutoIT.

I think IE download pop up is a windows event so cannot be handled by selenium directly, for this you'll have to use Java AWT or AutoIT.

AutoIT 脚本应该类似于

AutoIT script should be something similiar to

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

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

and save it as IEsave.exe. NOTE: I'haven't tried this AutoIT script.

现在您已经从您的程序中执行了 IEsave.exe.我这里用的是java.

now you have execute IEsave.exe from your program. I'm using java here.

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

这将执行该文件,该文件又将处理 Windows 的保存按钮事件.

This will execute the file which in-turn will handle the save button event for windows.

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

You can create similar exe files for handling other window's events.

希望这能解决您的问题.

Hope this solves your problem.

这篇关于窗口对话框Java 或 Javascript 中的弹出处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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