窗口对话框和放大器;在Java或JavaScript弹出处理 [英] Window Dialogs & Popup handling in Java or Javascript

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

问题描述

我需要操作的弹出窗口和放大器;使用Java或者IE浏览器的下载对话框
基于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.

任何建议是AP preciated。
谢谢你。

Any suggestion is appreciated. Thanks.

推荐答案

我用硒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(); 。这将返回包含在警告框为String的消息。

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(*铬)并执行code之前关闭所有其他窗口。

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

我希望这可以帮助你。

*所有提到的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下载弹出一个窗口事件,因此不能被直接硒处理,为此,你将不得不使用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。注:I'haven't尝试这个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");

这将执行,后者又将会处理保存按钮事件窗口中的文件。

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天全站免登陆