Window Dialogs & Popup handling in Java or Javascript

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

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.

Answers:

Answer

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

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());
        }

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

I hope this helps you.

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

EDIT

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 script should be something similiar to

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

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

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.

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

Hope this solves your problem.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.