1

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.

2
  • Use JS for this. Java would have to use JS on the side, so it just adds one more layer of complexity & chance for failure. Commented Apr 25, 2011 at 10:40
  • @Andrew Thompson: Thanks for your reply, Now I am able to handle alert/confirmation dialog with selenium2 driver itself, But for IE download dialog window I used AutoIT script as workaround. Still looking for smart solution for that ;) Commented Apr 26, 2011 at 18:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for reply, Its really helpful, actually I am using selenium2 WebDriverBackedSelenium to run the tests in IE8, I am able to manipulate alert/confirmation dialogs, but still not able to handle IE download dialog window which is having 'Open' / 'Save' / 'Cancel' buttons, I need to click 'Save', can you please help me out in this? Please provide some code with specific details if possible. Thanks.
@SmartSolution - I've updated the answer. Please refer it.Hope this helps.
Thanks 9ikhan. I am still facing issue with this AutoITscript. It works on local system and on RDP when RDP session is open. But when the RDP session is closed AutoITscript hangs. Do you know any work around to make AutoITscript work on closed RDP?
@SmartSolution, 9ikhan:: Is AutoIT works in RDP server? I'm using Robot class, but it didnt work in RDP server. I'm running my code in local and Browser is opening in Remote server through RemoteWebDriver option in Selenium. Can you please help me here with your inputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.