Skip to content

[🐛 Bug]: Multi tabs, after calling closeWindow , switchWindow fails with 'WebDriverError: no such window: target window already closed' #13882

@talbss

Description

@talbss

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.2.11

Node.js Version

v20.12.1

Mode

Standalone Mode

Which capabilities are you using?

'wdio:enforceWebDriverClassic': true

What happened?

I upgraded from wdio v8.33.0 to v9.2.11

What is your expected behavior?

After opening more than 2 tabs if i close the latest, I expect to be able to switchWindow to another opened tab.
It is not more possible with wdiov9 (it was ok with 8.33.0) as it fails with WebDriverError: no such window: target window already closed error.

How to reproduce the bug.

describe('open multiple tabs and closeWindow then switchWindow', function () {
  it('open multiple tabs and closeWindow then switchWindow', async function () {
    await browser.url('https://www.google.com/');
    await browser.newWindow('https://webdriver.io/docs/api/');
    await browser.newWindow('https://github.com/');
    await browser.pause(1000);
    await browser.closeWindow();
    await browser.switchWindow('google');

    /*
  //getting current handle also triggers the error
  let currentHandle = await browser.getWindowHandle();
  */
  });
});

Relevant log output

2024-11-14T16:24:20.087Z INFO @wdio/cli:launcher: Run onPrepare hook
2024-11-14T16:24:20.093Z DEBUG @wdio/cli:utils: Finished to run "onPrepare" hook in 3ms
2024-11-14T16:24:20.094Z INFO @wdio/utils: Setting up browser driver for: chrome@stable
2024-11-14T16:24:20.102Z INFO @wdio/utils: Setting up browser binaries for: chrome@stable
2024-11-14T16:24:20.266Z INFO webdriver: Using Chromedriver v131.0.6778.69 from cache directory C:\Users\me\Documents\\webdriverStorage
2024-11-14T16:24:20.514Z INFO webdriver: Setting up chrome v131.0.6778.69
2024-11-14T16:24:20.541Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2024-11-14T16:24:20.542Z DEBUG @wdio/cli:utils: Finished to run "onWorkerStart" hook in 1ms
2024-11-14T16:24:20.543Z INFO @wdio/local-runner: Start worker 0-0 with arg: testFull.conf.js --spec e2e\specs\test.spec.js
2024-11-14T16:24:20.551Z DEBUG @wdio/local-runner: Send command run to worker with cid "0-0"
[0-0] 2024-11-14T16:24:22.975Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2024-11-14T16:24:24.222Z DEBUG @wdio/runner: init remote session
[0-0] 2024-11-14T16:24:24.226Z DEBUG @wdio/utils:shim: Finished to run "beforeSession" hook in 0ms
[0-0] RUNNING in chrome - file:///C:/Users/me/Documents/e2e/specs/test.spec.js
[0-0] 2024-11-14T16:24:24.461Z DEBUG @wdio/runner: init remote session
[0-0] 2024-11-14T16:24:24.484Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2024-11-14T16:24:25.701Z INFO webdriver: Setting up chrome v131.0.6778.69
[0-0] 2024-11-14T16:24:25.737Z INFO webdriver: Using Chromedriver v131.0.6778.69 from cache directory C:\Users\me\Documents\\webdriverStorage
[0-0] 2024-11-14T16:24:25.769Z INFO chromedriver: Starting ChromeDriver 131.0.6778.69 (77e2244bbcda3ab9362d5b8aeeb006a86a6d4832-refs/branch-heads/6778@{#2141}) on port 56957
[0-0] 2024-11-14T16:24:25.770Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
[0-0] 2024-11-14T16:24:25.771Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[0-0] 2024-11-14T16:24:25.774Z INFO chromedriver: ChromeDriver was started successfully on port 56957.
[0-0] 2024-11-14T16:24:26.768Z INFO @wdio/utils: Started Chromedriver v131.0.6778.69 with params --port=56957 --allowed-origins=* --allowed-ips=0.0.0.0 in 1403ms on port 56957
[0-0] 2024-11-14T16:24:26.794Z INFO webdriver: [POST] http://localhost:56957/session
[0-0] 2024-11-14T16:24:26.794Z INFO webdriver: DATA {
[0-0]   capabilities: {
[0-0]     alwaysMatch: {
[0-0]       browserName: 'chrome',
[0-0]       acceptInsecureCerts: true,
[0-0]       'wdio:enforceWebDriverClassic': true,
[0-0]       browserVersion: 'stable',
[0-0]       'goog:chromeOptions': [Object]
[0-0]     },
[0-0]     firstMatch: [ {} ]
[0-0]   }
[0-0] }
[2292:20144:1114/172427.117:ERROR:sandbox_win.cc(791)] Sandbox cannot access executable. Check filesystem permissions are valid. See https://bit.ly/31yqMJR.: Acc├¿s refus├®. (0x5)

DevTools listening on ws://127.0.0.1:56983/devtools/browser/f1464e91-e855-42fc-b25d-dd2be36c6754
[2292:19064:1114/172427.274:ERROR:network_service_instance_impl.cc(613)] Network service crashed, restarting service.
[0-0] 2024-11-14T16:24:27.625Z INFO webdriver: COMMAND setWindowRect(null, null, 1920, 1080)
[0-0] 2024-11-14T16:24:27.627Z INFO webdriver: [POST] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/rect
[0-0] 2024-11-14T16:24:27.627Z INFO webdriver: DATA { x: null, y: null, width: 1920, height: 1080 }
[0-0] 2024-11-14T16:24:27.736Z INFO webdriver: RESULT { height: 1080, width: 1920, x: 10, y: 10 }
[0-0] 2024-11-14T16:24:27.738Z DEBUG @wdio/utils:shim: Finished to run "before" hook in 116ms
[0-0] 2024-11-14T16:24:27.755Z DEBUG @wdio/utils:shim: Finished to run "beforeTest" hook in 3ms
[0-0] 2024-11-14T16:24:27.758Z INFO webdriver: COMMAND navigateTo("https://www.google.com/")
[0-0] 2024-11-14T16:24:27.759Z INFO webdriver: [POST] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/url
[0-0] 2024-11-14T16:24:27.760Z INFO webdriver: DATA { url: 'https://www.google.com/' }
[0-0] 2024-11-14T16:24:28.826Z INFO webdriver: RESULT null
[0-0] 2024-11-14T16:24:28.828Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-11-14T16:24:28.829Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/handles
[0-0] 2024-11-14T16:24:28.844Z INFO webdriver: RESULT [ '63AECD1F8EB92E6E6691BFC8451343B8' ]
[0-0] 2024-11-14T16:24:28.845Z INFO webdriver: COMMAND executeScript("
[0-0]             var __defProp = Object.defineProperty;var __name = function (target, value) { return __defProp(target, 'name', { value: value, configurable: true }); };var __globalThis = (typeof globalThis === 'object' && globalThis) || (typeof window === 'object' && window);__globalThis.__name = __name;
[0-0]             return (function newWindow(url, windowName, windowFeatures) {
[0-0]   window.open(url, windowName || "", windowFeatures || "");
[0-0] }).apply(null, arguments)
[0-0]         ", <object>)
[0-0] 2024-11-14T16:24:28.846Z INFO webdriver: [POST] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/execute/sync
[0-0] 2024-11-14T16:24:28.846Z INFO webdriver: DATA {
[0-0]   script: 'newWindow(...) [471 bytes]',
[0-0]   args: [ 'https://webdriver.io/docs/api/', '', '' ]
[0-0] }
[0-0] 2024-11-14T16:24:28.914Z INFO webdriver: RESULT null
[0-0] 2024-11-14T16:24:28.915Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-11-14T16:24:28.916Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/handles
[0-0] 2024-11-14T16:24:28.938Z INFO webdriver: RESULT [
[0-0]   '63AECD1F8EB92E6E6691BFC8451343B8',
[0-0]   'EB182F79E192981E0B7706346D460F67'
[0-0] ]
[0-0] 2024-11-14T16:24:28.940Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-11-14T16:24:28.941Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/handles
[0-0] 2024-11-14T16:24:28.957Z INFO webdriver: RESULT [
[0-0]   '63AECD1F8EB92E6E6691BFC8451343B8',
[0-0]   'EB182F79E192981E0B7706346D460F67'
[0-0] ]
[0-0] 2024-11-14T16:24:28.959Z INFO webdriver: COMMAND switchToWindow("<Screenshot[base64]>")
[0-0] 2024-11-14T16:24:28.960Z INFO webdriver: [POST] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:28.961Z INFO webdriver: DATA { handle: 'EB182F79E192981E0B7706346D460F67' }
[0-0] 2024-11-14T16:24:28.987Z INFO webdriver: RESULT null
[0-0] 2024-11-14T16:24:28.988Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-11-14T16:24:28.989Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/handles
[0-0] 2024-11-14T16:24:29.004Z INFO webdriver: RESULT [
[0-0]   '63AECD1F8EB92E6E6691BFC8451343B8',
[0-0]   'EB182F79E192981E0B7706346D460F67'
[0-0] ]
[0-0] 2024-11-14T16:24:29.006Z INFO webdriver: COMMAND executeScript("
[0-0]             var __defProp = Object.defineProperty;var __name = function (target, value) { return __defProp(target, 'name', { value: value, configurable: true }); };var __globalThis = (typeof globalThis === 'object' && globalThis) || (typeof window === 'object' && window);__globalThis.__name = __name;
[0-0]             return (function newWindow(url, windowName, windowFeatures) {
[0-0]   window.open(url, windowName || "", windowFeatures || "");
[0-0] }).apply(null, arguments)
[0-0]         ", <object>)
[0-0] 2024-11-14T16:24:29.007Z INFO webdriver: [POST] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/execute/sync
[0-0] 2024-11-14T16:24:29.007Z INFO webdriver: DATA {
[0-0]   script: 'newWindow(...) [471 bytes]',
[0-0]   args: [ 'https://github.com/', '', '' ]
[0-0] }
[0-0] 2024-11-14T16:24:30.246Z INFO webdriver: RESULT null
[0-0] 2024-11-14T16:24:30.247Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-11-14T16:24:30.248Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/handles
[0-0] 2024-11-14T16:24:30.341Z INFO webdriver: RESULT [
[0-0]   '63AECD1F8EB92E6E6691BFC8451343B8',
[0-0]   'EB182F79E192981E0B7706346D460F67',
[0-0]   'B62FF6E9ECFB80B484601C697047DB42'
[0-0] ]
[0-0] 2024-11-14T16:24:30.343Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-11-14T16:24:30.344Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window/handles
[0-0] 2024-11-14T16:24:30.359Z INFO webdriver: RESULT [
[0-0]   '63AECD1F8EB92E6E6691BFC8451343B8',
[0-0]   'EB182F79E192981E0B7706346D460F67',
[0-0]   'B62FF6E9ECFB80B484601C697047DB42'
[0-0] ]
[0-0] 2024-11-14T16:24:30.361Z INFO webdriver: COMMAND switchToWindow("<Screenshot[base64]>")
[0-0] 2024-11-14T16:24:30.362Z INFO webdriver: [POST] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:30.362Z INFO webdriver: DATA { handle: 'B62FF6E9ECFB80B484601C697047DB42' }
[0-0] 2024-11-14T16:24:30.372Z INFO webdriver: RESULT null
[0-0] 2024-11-14T16:24:31.414Z INFO webdriver: COMMAND closeWindow()
[0-0] 2024-11-14T16:24:31.416Z INFO webdriver: [DELETE] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:31.830Z INFO webdriver: RESULT [
[0-0]   '63AECD1F8EB92E6E6691BFC8451343B8',
[0-0]   'EB182F79E192981E0B7706346D460F67'
[0-0] ]
[0-0] 2024-11-14T16:24:31.832Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2024-11-14T16:24:31.833Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:31.840Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:31.841Z WARN webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "window" with method "GET"
[0-0] 2024-11-14T16:24:31.842Z INFO webdriver: Retrying 1/3
[0-0] 2024-11-14T16:24:31.843Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:31.856Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:32.365Z WARN webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "window" with method "GET"
[0-0] 2024-11-14T16:24:32.367Z INFO webdriver: Retrying 2/3
[0-0] 2024-11-14T16:24:32.367Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:32.374Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:33.384Z WARN webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "window" with method "GET"
[0-0] 2024-11-14T16:24:33.385Z INFO webdriver: Retrying 3/3
[0-0] 2024-11-14T16:24:33.385Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/window
[0-0] 2024-11-14T16:24:33.391Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:33.391Z ERROR webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "window" with method "GET"
[0-0] 2024-11-14T16:24:33.440Z INFO webdriver: COMMAND takeScreenshot()
[0-0] 2024-11-14T16:24:33.441Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/screenshot
[0-0] 2024-11-14T16:24:33.446Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:33.446Z WARN webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "screenshot" with method "GET"
[0-0] 2024-11-14T16:24:33.447Z INFO webdriver: Retrying 1/3
[0-0] 2024-11-14T16:24:33.447Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/screenshot
[0-0] 2024-11-14T16:24:33.455Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:33.963Z WARN webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "screenshot" with method "GET"
[0-0] 2024-11-14T16:24:33.964Z INFO webdriver: Retrying 2/3
[0-0] 2024-11-14T16:24:33.964Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/screenshot
[0-0] 2024-11-14T16:24:33.971Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:34.973Z WARN webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "screenshot" with method "GET"
[0-0] 2024-11-14T16:24:34.974Z INFO webdriver: Retrying 3/3
[0-0] 2024-11-14T16:24:34.975Z INFO webdriver: [GET] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c/screenshot
[0-0] 2024-11-14T16:24:34.983Z DEBUG webdriver: request failed due to response error: no such window
[0-0] 2024-11-14T16:24:34.983Z ERROR webdriver: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "screenshot" with method "GET"
[0-0] 2024-11-14T16:24:34.985Z ERROR @wdio/utils:shim: no such window: WebDriverError: no such window: target window already closed
[0-0] from unknown error: web view not found
[0-0]   (Session info: chrome=131.0.6778.69) when running "screenshot" with method "GET"
[0-0]     at FetchRequest._request (C:\Users\me\Documents\\node_modules\webdriver\build\index.js:1373:19)
[0-0]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[0-0]     at Browser.wrapCommandFn (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:884:23)
[0-0]     at async Object.afterTest (file:///C:/Users/me/Documents/shared.conf.js:438:7)
[0-0]     at async Promise.all (index 0)
[0-0]     at executeHooksWithArgs (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:867:18)
[0-0]     at Context.testFrameworkFnWrapper (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:1103:38)
[0-0] 2024-11-14T16:24:34.986Z DEBUG @wdio/utils:shim: Finished to run "afterTest" hook in 1546ms
[0-0] Error in "AfterTest Hook"
WebDriverError: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=131.0.6778.69) when running "screenshot" with method "GET"
[0-0] no such window in "open multiple tabs and closeWindow then switchWindow.open multiple tabs and closeWindow then switchWindow"
no such window: WebDriverError: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=131.0.6778.69) when running "window" with method "GET"
    at FetchRequest._request (C:\Users\me\Documents\\node_modules\webdriver\build\index.js:1373:19)
    at Browser.wrapCommandFn (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:884:23)
    at Browser.switchWindow (C:\Users\me\Documents\\node_modules\webdriverio\build\index.js:4144:25)
    at Browser.wrapCommandFn (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:884:23)
    at async Context.<anonymous> (file:///C:/Users/me/Documents/e2e/specs/test.spec.js:8:5)
    at Context.executeAsync (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:1004:20)
    at Context.testFrameworkFnWrapper (C:\Users\me\Documents\\node_modules\@wdio\utils\build\index.js:1075:14)
[0-0] 2024-11-14T16:24:34.992Z DEBUG @wdio/utils:shim: Finished to run "after" hook in 1ms
[0-0] 2024-11-14T16:24:34.993Z INFO webdriver: COMMAND deleteSession()
[0-0] 2024-11-14T16:24:34.993Z INFO webdriver: [DELETE] http://localhost:56957/session/8d3fc59d4972892622927cee678a045c
[0-0] 2024-11-14T16:24:35.390Z INFO webdriver: RESULT null
[0-0] 2024-11-14T16:24:35.391Z INFO webdriver: Kill driver process with PID 3780
2024-11-14T16:24:35.634Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
[0-0] FAILED in chrome - file:///C:/Users/me/Documents/e2e/specs/test.spec.js
2024-11-14T16:24:35.636Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
2024-11-14T16:24:35.643Z DEBUG @wdio/cli:utils: Finished to run "onWorkerEnd" hook in 0ms
2024-11-14T16:24:35.644Z INFO @wdio/cli:launcher: Run onComplete hook

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions