Handling browser pop-up windows with Selenium

63,844

Solution 1

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>

Solution 2

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.

Share:
63,844
brasskazoo
Author by

brasskazoo

I am a Software and Cloud Solutions Engineer with a passion for building quality and automation into the development, testing and deployment lifecycles. Currently working with a large AWS hybrid-cloud integration project, including VPC architecting and solution design, serverless applications and shifting applications to EC2. Primarily I work with terraform, node.js, react and java, with side projects currently in react-native and GraphQL for cross-platform mobile applications. Agile, DevOps culture, Code Quality and Continuous Integration are cornerstones of my development efforts.

Updated on July 09, 2022

Comments

  • brasskazoo
    brasskazoo almost 2 years

    We are running Selenium regression tests against our existing code base, and certain screens in our web app use pop-ups for intermediate steps.

    Currently we use the commands in the test:

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

    ...which works most of the time. Occasionally the test will fail on the waitForPopUp() line with

    com.thoughtworks.selenium.SeleniumException: Permission denied
    

    Can anyone suggest a better, more reliable method?

    Also, we primarily run these tests on IE6 and 7.

  • brasskazoo
    brasskazoo almost 16 years
    Oh believe me, I wish we could just run it in firefox! But 99% of our users are on IE so that is the priority for testing... We use *iexplore, not *iehta too. I'm not aware of the differences?
  • Josh
    Josh almost 16 years
    *iehta and *chrome allow for https support. This way you don't have to worry about the problems that arise from certificates.
  • brasskazoo
    brasskazoo over 15 years
    For the moment, it has been working, so I'm going to extend it across all tests using popups (we are eventually moving to lightboxes).
  • Chris Noe
    Chris Noe over 14 years
    This doesn't work for me unless I move windowFocus to the last command issued. It doesn't make any sense for it to be before the waitForPopUp, does it?