Handling browser pop-up windows with Selenium Handling browser pop-up windows with Selenium selenium selenium

Handling browser pop-up windows with Selenium


It works!! Just to make it easier for the folks who prefer selenese.

This worked for me using IE7(normal mode).

What a freaking hassle. Thank the spaghetti monster in the sky for SO or there is no way I would have got this working in IE.

<tr>    <td>getEval</td>    <td>selenium.browserbot.getCurrentWindow().open('', 'windowName');</td>    <td></td></tr><tr>    <td>click</td>    <td>buttonName</td>    <td></td></tr><tr>    <td>windowFocus</td>    <td>windowName</td>    <td></td></tr><tr>    <td>waitForPopUp</td>    <td>windowName</td>    <td>3000</td></tr><tr>    <td>selectWindow</td>    <td>windowName</td>    <td></td></tr>


If you are running in *iehta mode then you are going to run into some glitches here and there. We run Selenium at my job and there seem to be lots of issues with IE and AJAX.

However, it sounds like the issue you are running into is one where Selenium is trying to access a component in another window before it completely loads up. I am not sure what your default timeout range is set to, but you may want to try increasing it to 60 (60000ms) seconds or so to get past the issue.

Other than that I would suggest running your tests in Firefox (using *chrome) as it produces much more reliable results, but sometimes it is simply not possible due to business requirements.


I just trialled adding another selenium function, windowFocus():

// force new window to open at this point - so we can select it laterselenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");selenium().click("//input[@value='Submit']");selenium().windowFocus("enquiryPopup");selenium().waitForPopUp("enquiryPopup", getWaitTime());selenium().selectWindow("enquiryPopup");

The test succeeded when I ran it locally, but only with all those method calls - create/focus/wait/select.

I'm about to let the build server run all the tests, and if that succeeds too, I'll be making a library function out of it...!