Can't switch windows in SafariDriver, but works fine with any other browser

896 views
Skip to first unread message

Jared Ning

unread,
Sep 12, 2016, 10:29:58 PM9/12/16
to webdriver
Hi,

I have a link that opens in a new window. I'm using the following code to do the switch:

String parentWindowHandler = driver.getWindowHandle();
String subWindowHandler = null;

Set<String> handles = driver.getWindowHandles();
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext())
{
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler);

//code to be executed in the new window

driver.close();
driver.switchTo().window(parentWindowHandler);

This code works with IE, Firefox, Chrome, and Opera perfectly fine. However, with SafariDriver, my code hangs after I reach the //code to be executed in the new window line, and I get a NoSuchElementException. The only way I can get SafariDriver to execute any commands in the new window is by executing the first command manually; in my case I click a button on the new window, and then the rest of the code executes properly. So it seems to me that the window focus isn't successfully switching for SafariDriver.

Is there any way to get this to work with SafarDriver? I haven't seen this issue anywhere from my searching online and I'm not sure what to do. Any help is appreciated!

Thanks,

Jared



darrell grainger

unread,
Sep 13, 2016, 9:28:22 AM9/13/16
to webdriver
Have you had a look at https://github.com/SeleniumHQ/selenium/wiki/SafariDriver. I have not tried testing against Safari since 2012 but I remember around 2011 there was a lot of issues around support for Safari. Around 2012 there was renewed support for SafariDriver but it had a lot of issues the other drivers did not have. If you go to the page above there is a link to known issues as well as a link to submit a defect.

Additionally, since Apple dropped support for Safari on Windows I have seen a steady decline in Safari usage according to client analytics. Most public stats have Safari usage below 5% for the last decade. My client analytics show Safari usage below 1% usage. Based on the effort required to support Safari versus the number of people still using it means many people are just doing a basic smoke test or nothing at all.

Oddly enough, secure government websites seem to be the only sites I use, personally, which ONLY work with Safari on Mac.

Jared Ning

unread,
Sep 13, 2016, 11:43:37 AM9/13/16
to webdriver
Thanks for the reply Darrell! I've managed to convince the higher ups to drop testing for Safari so I think everything should be good for me now :)

David

unread,
Sep 14, 2016, 5:15:26 PM9/14/16
to webdriver
Darrell, which public stats were you referring to? Would be interesting to know, regarding the stats source.

Where I previously worked, (Mac) Safari usage by our customer base was still high enough to warrant coverage, but I don't recall the exact figures. But of course, it's a case by case basis for each company/website for Safari usage.

Apple is supporting their own SafariDriver in Mac Sierra, so hopefully that's a step up for the future than what we currently have for Safari automation support.

darrell grainger

unread,
Sep 15, 2016, 8:02:10 AM9/15/16
to webdriver
The stats I was relying on were supplied to me from another team but I believe they were using W3Schools, StatCounter and there was a third one they said they were using. I think the third one was Net Market Share.

It should be noticed that by Safari I mean the desktop application. Safari as a mobile/tablet browser is a different story. Testing against mobile browsers are definitely on the rise.

It is good to hear that Apple is going to be support SafariDriver in the future. I'm a huge fan of WebDriver and Selenium. It was incredibly frustrating when I was working for a company that was 100% Apple/Safari and I could not find any support for SafariDriver. Since that time all my clients have been telling me that out of all desktop browsers they aren't willing to support Safari. Had one customer who actually had us put in a popup; if it detected you were using Safari it recommended you switch to Chrome.
Reply all
Reply to author
Forward
0 new messages