Skip to content

Commit

Permalink
[java] search windows by name without recursion #14782
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Nov 21, 2024
1 parent e9c09a2 commit 99ee404
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,12 +1148,16 @@ public WebDriver window(String windowHandleOrName) {
// simulate search by name
String original = getWindowHandle();
for (String handle : getWindowHandles()) {
switchTo().window(handle);
if (windowHandleOrName.equals(executeScript("return window.name"))) {
return RemoteWebDriver.this; // found by name
try {
execute(DriverCommand.SWITCH_TO_WINDOW(handle));
if (windowHandleOrName.equals(executeScript("return window.name"))) {
return RemoteWebDriver.this; // found by name
}
} catch (NoSuchWindowException nswe) {
// swallow
}
}
switchTo().window(original);
execute(DriverCommand.SWITCH_TO_WINDOW(original));
throw nsw;
}
}
Expand Down

0 comments on commit 99ee404

Please sign in to comment.