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