Fix obscure window switching bug
Fixes searching by window name if the current window handle becomes
invalid and the name being switched to does not exist.
@@ -146,7 +146,15 @@ public IWebDriver Window(string windowHandleOrName)
catch (NoSuchWindowException)
{
// simulate search by name
- string original = this.driver.CurrentWindowHandle;
+ string original = null;
+ try
+ {
+ original = this.driver.CurrentWindowHandle;
+ }
+ catch (NoSuchWindowException)
+ {
+ }
+
foreach (string handle in this.driver.WindowHandles)
{
this.Window(handle);
@@ -156,7 +164,11 @@ public IWebDriver Window(string windowHandleOrName)
}
}
+ if (original != null)
+ {
this.Window(original);
+ }
+
throw;
}
}
