-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
What happened?
-
Using Selenium Java I wrote a step that depended on counting how many window handles there are. When a tab opens that contains a PDF (it is connected to report genertion, but I tried manually inserting a PDF inside a tab and it behaved the same way) instead of adding 1 window handle to the Set, 2 window handles are added. So for example if I have 1 tab open, I click on 'Generate report', a PDF report appears, 2 tabs are open seemingly in the browser, but the size of
driver.getWindowHandles()is 3. -
While counting it is also a problem, closing them does not work in a striaghtforward
driver.close()manner either.
It times out with the following error:org.openqa.selenium.WebDriverException: unknown error: failed to close window in 20 seconds. -
For a workaround I used
((JavascriptExecutor) driver).executeScript("window.close()");. While this works, and closes the tab, it is certain that the actual and 'shadow' tab are tied, because it does not matter which one I close with the above command, the actual tab closes in the browser, and both window handles disappear.
How can we reproduce the issue?
Reproducing this is simple enough with a `main()` method.
public static void main(String [] args) {
ChromeDriver chromeDriver = new ChromeDriver;
chromeDriver.get("www.google.com");
System.out.println("Stop");
}
1. Run it in debug, stop at the third line with a breakpoint.
2. With debugging tools run `chromeDriver.getWindowHandles().size()`. It should result in `1`.
3. In the opened browser open a new tab, find a pdf in your system and drag it inside to open it in the same Chrome window. Now there are 2 tabs open in the browser.
4. Run the 2. point again, but is should result in `3`
I expect it to result in `2`Relevant log output
Step failed
org.openqa.selenium.WebDriverException: unknown error: failed to close window in 20 seconds
(Session info: chrome=133.0.6943.127)
Build info: version: '4.27.0', revision: 'd6e718d134'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '21.0.4'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [27c7ce8291b8969c47c3a709920d08a6, close {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 133.0.6943.127, chrome: {chromedriverVersion: 133.0.6943.126 (cffa127ce7b..., userDataDir: C:\Users\BELLRR~1\AppData\L...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:51702}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(), se:cdp: ws://localhost:51702/devtoo..., se:cdpVersion: 133.0.6943.127, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 27c7ce8291b8969c47c3a709920d08a6
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)Operating System
Windows 10
Selenium version
Java 4.27.0
What are the browser(s) and version(s) where you see this issue?
Chrome 133
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 133
Are you using Selenium Grid?
No