Description
The RemoteTargetLocator does store the old handle before switching, this fails (in accordance with the W3C webdriver spec). The webdriver is stuck and we must first switch back to an open window to open a new window.
I think the try-catch block can be removed here, as it is unlikely we can not switch to the just created handle.
And if this rare case happens, we should be still on the old handle, so no need to go back to it.
Reproducible Code
driver.switchTo().newWindow(WindowType.WINDOW);
driver.switchTo().close(); // we still have the orignal window open
driver.switchTo().newWindow(WindowType.WINDOW); // <- fails with:
org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
at org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:169)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:142)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:223)
at com.mercedes.benz.tech.innovation.automation.driver.factory.SeleniumDrivers$1.execute(SeleniumDrivers.java:192)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at com.mercedes.benz.tech.innovation.automation.driver.factory.SeleniumDrivers$2.execute(SeleniumDrivers.java:207)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:686)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:690)
at org.openqa.selenium.remote.RemoteWebDriver.getWindowHandle(RemoteWebDriver.java:527)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.newWindow(RemoteWebDriver.java:1303)
Description
The
RemoteTargetLocatordoes store the old handle before switching, this fails (in accordance with the W3C webdriver spec). The webdriver is stuck and we must first switch back to an open window to open a new window.I think the try-catch block can be removed here, as it is unlikely we can not switch to the just created handle.
And if this rare case happens, we should be still on the old handle, so no need to go back to it.
Reproducible Code