getWindowHandles() returns 1 after popup window appears

97 views
Skip to first unread message

Stephen Kurlow

unread,
Aug 26, 2014, 2:48:21 AM8/26/14
to seleniu...@googlegroups.com
I am using IEDriverServer 2.42 with selenium 2.42 in Java. Tell me if you need more info.

Some javascript executes to open a new window using window.open(...) and after the new window appears when my Java app executes getWindowHandles() it only returns 1 item instead of 2. I have searched high and low using google but alas I cannot find a reason why getWindowHandles() is returning 1 item instead of 2.

Please help or at least ask for more info as I am not sure what to give to help out.

Thanks!

Jim Evans

unread,
Aug 26, 2014, 6:24:18 AM8/26/14
to seleniu...@googlegroups.com
If you've searched high and low, then you already know the most common causes of the symptoms you describe. At the very least, you should be able to provide that information.

The first most common cause is not waiting for the new window to appear before checking the result of getWindowHandles(). Try a Thread.sleep() to see if that fixes it. If it does, replace the hard-coded sleep() with something more appropriate, like a WebDriverWait.

The second most common cause is for Protected Mode settings to not be set the same for all zones. A quick search via Google on "WebDriver protected mode" shows a blog post that fully describes why it's needed, and why you should never use the "INTRODUCE_FLAKINESS" desired capability.

This functionality is not globally broken for all web sites with the IE driver. If it's not one of those two causes, further troubleshooting without an example page will be next to impossible.

Stephen Kurlow

unread,
Aug 26, 2014, 6:54:21 PM8/26/14
to seleniu...@googlegroups.com
Hi Jim,

Thanks for your time.

1) I have debugged my java selenium test app and waited for the popup window to appear and then called getWindowHandles() and it still only returns 1. Interestingly there are 2 different popups that can be opened from two different buttons on my page. For one of them getWindowHandles() returns 2. Something I've noticed which may or may not be important is that the popup I can get a handle too is modal in appearance, ie. cannot give focus to the parent window. The popup that I cannot get a handle too is NOT modal in appearance, I can give focus to the parent window and close it and the popup then becomes orphaned.

2) Yes I did read about protected mode in some posts and it is not set the same for all zones. I will have to check with some security people where I work to see whether they are willing to change it. I thought this might not be the issue considering as in 1) above getWindowHandles() can return 2 for just one of the popups we have.

Our web app is only available on our intranet so what do you need from our example pages to investigate further?

Thanks very much,
Stephen

Jim Evans

unread,
Aug 26, 2014, 11:17:45 PM8/26/14
to seleniu...@googlegroups.com
You must set the Protected Mode settings for the browser. If you are unable to do so, you're in unsupported territory. The documentation is very clear on this point. Depending on the method used by the application to open the new browser window (window.open included), the new window could cross a Protected Mode boundary. If a Protected Mode boundary is crossed, the driver can't communicate with it. Full stop. That's why it's critical that Protected Mode boundaries not be crossed; the *only* way to guarantee boundaries don't get crossed is to set the setting to the same value for all zones.

To further troubleshoot the issue, we would need a sample set of pages that reproduce the problem. If you're unwilling[1] to provide a sample set of pages, there's no hope of being able to find the issue.

--Jim

[1] Yes, unwilling, not unable. See http://jimevansmusic.blogspot.com/2012/12/not-providing-html-page-is-bogus.html for reasons why I use this strident wording.

Stephen Kurlow

unread,
Aug 26, 2014, 11:49:08 PM8/26/14
to seleniu...@googlegroups.com
OK thanks again Jim for your valuable time!

I'm waiting for someone from our security administration team to get back to me on setting the Protected Mode to be the same. I presume it should be enabled for each zone or off or it doesn't matter which one?

If I still run into an issue after the Protected Mode settings change then I will be willing to give some HTML code. :-)

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/Fy7wSGV_Kn0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/58ebffff-08f3-4cc0-b481-391f82287add%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages