From 99ee404532924e4e21db387fd6bca82de6ad5f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Thu, 21 Nov 2024 20:51:09 +0100 Subject: [PATCH] [java] search windows by name without recursion #14782 --- .../org/openqa/selenium/remote/RemoteWebDriver.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java index 58f08763b2ebd..737be829226d7 100644 --- a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java +++ b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java @@ -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; } }