From e51028469f7f994286054e2c468618a192c7ed13 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 10 Apr 2024 10:43:36 +0300 Subject: [PATCH] Close all, but main window during session reset --- src/Selenium2Driver.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 7933c4df..36a9353c 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -403,7 +403,20 @@ public function stop() public function reset() { - $this->getWebDriverSession()->deleteAllCookies(); + $webDriverSession = $this->getWebDriverSession(); + + // Close all windows except the initial one. + foreach ($webDriverSession->window_handles() as $windowHandle) { + if ($windowHandle === $this->initialWindowHandle) { + continue; + } + + $webDriverSession->focusWindow($windowHandle); + $webDriverSession->deleteWindow(); + } + + $this->switchToWindow(); + $webDriverSession->deleteAllCookies(); } public function visit(string $url)