tags:

views:

324

answers:

1

When using Selenium how can I wait for a popup window if its id is dynamically generated? For example:

selenium.click("link=mylink");
selenium.waitForPopUp("popup072815372337691199");

Obviously I cannot hardcode the window id in my source code. Any hints?

+1  A: 

It would obviously be best to have a consistent or fully predictable window name, however if this is not possible you could try using the getAllWindowNames command to wait until the number of windows increments. If the name of the window is somewhat predictable (like a consistent prefix) you could then find out the full name of the new window before using waitForPopup or selectWindow.

Dave Hunt
I wanted to say the same thing, but a popup is not a window isn't it? So getAllWindow would not get it... Or if it would then you could use a regex to search for it. But that's the whole point that you don't know the id that you are looking for.So you could use something like :popup/d+
Hannibal
With getAllWindowNames() or getAllWindowIds() it is possible to retrieve the popup window's name. The problem is that right after selenium.click() these methods don't find the popup. I would have to wait for "some" seconds until the popup window is found. So I have the same problem that I don't know the time to wait until I get a reliable result.
Peter
The idea with the regex is a good one, but it will only work for the "popupXXX" pattern. What if I have no idea at all how the windowId of the popup will look like?
Peter
`waitForPopup` is for actual windows. If you're using Selenium RC then you can 'wait' until the window exists by having a loop continuously evaluating the result of `getAllWindowNames`. You can probably even do this in Selenium IDE by making clever use of the `waitForCondition` command.
Dave Hunt
Thanks for the hint! I solved it now with a loop...
Peter
Your welcome. Might be worth sharing your solution as an answer to your own question - to help others with the same issue.
Dave Hunt