Skip to content

[🐛 Bug]: NoSuchWindowException occurring when checking page element #16266

@kmcdowell-mp

Description

@kmcdowell-mp

Description

This NoSuchWindowException randomly, but somewhat consistently, reproduces. It frequently happens on the first time run, or on subsequent passes (the signIn method gets called every 5 tests because large 3D models are loaded in the browser session and eventually cause an Error: Out of memory page in Chrome, unless I kill the browser session and driver and restart it). It had run consistently for several weeks with no issues until about Aug 14. After digging in and finding no solutions online or getting any responses on StackOverflow, I decided it was time to file the bug.

Reproducible Code

This is the first method called in my Selenium testing application (commented lines were used for trying to debug the issue)

async def signIn():
    global driver
    """Signs in to QA3 based on the credentials provided with the developer tools open and logging started
    """    
    driver = None
    # isChromeDriverRunning = False
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--enable-logging')
    chrome_options.add_argument("--auto-open-devtools-for-tabs")
    chrome_options.set_capability('goog:loggingPrefs', {'performance': 'ALL'})

    driver = webdriver.Chrome(options=chrome_options)
    # print(f"Driver window handle:{driver.current_window_handle}")
    # print(f"Driver session id:{driver.session_id}")
    # time.sleep(1)

    # while not isChromeDriverRunning:
    #     time.sleep(1)
    #     isChromeDriverRunning = isProcessRunning("chromedriver")
    #     print(f"Found chromedriver: {isChromeDriverRunning})")
    
    # driver.execute_cdp_cmd("Log.enable", {})
    # driver.execute_cdp_cmd("Network.enable", {})
    # driver.execute_cdp_cmd("Performance.enable", {})
    driver.get(loginURL)
    errors = await waitForElementVisibilityBy(driver, By.ID, "email", 10)

And this is the `waitForElementVisibilityBy` method:

async def waitForElementVisibilityBy(driver: webdriver, by: By, value, timeout = 2):
    try:
        WebDriverWait(driver, timeout, .2).until(EC.visibility_of_any_elements_located((by, value)))
        return [True]
    except Exception as e:
        print(e)
        return [False, e, value]


Just trying to check the visibility of the email textbox is returning a `NoSuchWindowException`.  When I step through the code, the internal call (on line 508 of URLLib3's connection.py module - self.send(chunk)) to send the URL to the client-side server via `driver.get(loginUrl)` is returning a 200, but the browser URL never updates and the page does not load.

Debugging Logs

Selenium Manager binary found at: C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\selenium\webdriver\common\windows\selenium-manager.exe
Executing process: C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --debug --language-binding python --output json
Sending stats to Plausible: Props { browser: "chrome", browser_version: "", os: "windows", arch: "x86_64", lang: "python", selenium_version: "4.35" }
chromedriver not found in PATH
chrome detected at C:\Program Files\Google\Chrome\Application\chrome.exe
Detected browser: chrome 139.0.7258.155
Required driver: chromedriver 139.0.7258.154
chromedriver 139.0.7258.154 already in the cache
Driver path: C:\Users\me\.cache\selenium\chromedriver\win64\139.0.7258.154\chromedriver.exe
Browser path: C:\Program Files\Google\Chrome\Application\chrome.exe
Started executable: `C:\Users\me\.cache\selenium\chromedriver\win64\139.0.7258.154\chromedriver.exe` in a child process with pid: 16548 using 0 to output -3
POST http://localhost:51041/session {'capabilities': {'firstMatch': [{}], 'alwaysMatch': {'browserName': 'chrome', 'pageLoadStrategy': <PageLoadStrategy.normal: 'normal'>, 'goog:loggingPrefs': {'performance': 'ALL'}, 'browserVersion': None, 'goog:chromeOptions': {'extensions': [], 'binary': 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', 'args': ['--enable-logging', '--auto-open-devtools-for-tabs']}}}}

DevTools listening on ws://127.0.0.1:51066/devtools/browser/ea67ab6f-b7a3-4341-bbca-a887859ae842
Remote response: status=200 | data={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"139.0.7258.155","chrome":{"chromedriverVersion":"139.0.7258.154 (9e0d6b2b47ffb17007b713429c9a302f9e43847f-refs/branch-heads/7258@{#2926})","userDataDir":"C:\\Users\\KMCDOW~1\\AppData\\Local\\Temp\\scoped_dir16548_1933354804"},"fedcm:accounts":true,"goog:chromeOptions":{"debuggerAddress":"localhost:51066"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"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},"sessionId":"c268de61127e61d5d64008237976591c"}} | headers=HTTPHeaderDict({'Content-Length': '887', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
GET http://localhost:51041/session/c268de61127e61d5d64008237976591c/window {}
Remote response: status=200 | data={"value":"3240465593A99B4702A26EFEF52795C6"} | headers=HTTPHeaderDict({'Content-Length': '44', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
Driver window handle:3240465593A99B4702A26EFEF52795C6
Driver session id:c268de61127e61d5d64008237976591c
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1756335813.752546   55500 voice_transcription.cc:58] Registering VoiceTranscriptionCapability
[43544:21052:0827/160334.322:ERROR:google_apis\gcm\engine\registration_request.cc:291] Registration response error message: DEPRECATED_ENDPOINT
Found chromedriver: True)
POST http://localhost:51041/session/c268de61127e61d5d64008237976591c/goog/cdp/execute {'cmd': 'Log.enable', 'params': {}}
Remote response: status=200 | data={"value":{}} | headers=HTTPHeaderDict({'Content-Length': '12', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})      
Finished Request
POST http://localhost:51041/session/c268de61127e61d5d64008237976591c/goog/cdp/execute {'cmd': 'Network.enable', 'params': {}}
Remote response: status=200 | data={"value":{}} | headers=HTTPHeaderDict({'Content-Length': '12', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})      
Finished Request
POST http://localhost:51041/session/c268de61127e61d5d64008237976591c/goog/cdp/execute {'cmd': 'Performance.enable', 'params': {}}
Remote response: status=200 | data={"value":{}} | headers=HTTPHeaderDict({'Content-Length': '12', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
POST http://localhost:51041/session/c268de61127e61d5d64008237976591c/url {'url': 'https://qauth.noneofyourbusiness.com/login'}
[43544:57064:0827/160335.275:ERROR:chrome\browser\devtools\devtools_ui_bindings.cc:2589] Attempt to navigate to an invalid DevTools front-end URL: https://qauth.noneofyourbusiness.com/login
Remote response: status=200 | data={"value":null} | headers=HTTPHeaderDict({'Content-Length': '14', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
POST http://localhost:51041/session/c268de61127e61d5d64008237976591c/elements {'using': 'css selector', 'value': '[id="email"]'}
Remote response: status=404 | data={"value":{"error":"no such window","message":"no such window: target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=139.0.7258.155)","stacktrace":"\tGetHandleVerifier [0x0x7ff7134b3d85+79397]\n\tGetHandleVerifier [0x0x7ff7134b3de0+79488]\n\t(No symbol) [0x0x7ff71325c0fa]\n\t(No symbol) [0x0x7ff713234601]\n\t(No symbol) [0x0x7ff7132e257e]\n\t(No symbol) [0x0x7ff713302c72]\n\t(No symbol) [0x0x7ff7132daf73]\n\t(No symbol) [0x0x7ff7132a41b1]\n\t(No symbol) [0x0x7ff7132a4f43]\n\tGetHandleVerifier [0x0x7ff71377e1ed+3005069]\n\tGetHandleVerifier [0x0x7ff71377831d+2980797]\n\tGetHandleVerifier [0x0x7ff713797e0d+3110573]\n\tGetHandleVerifier [0x0x7ff7134cd6de+184190]\n\tGetHandleVerifier [0x0x7ff7134d516f+215567]\n\tGetHandleVerifier [0x0x7ff7134bc974+115220]\n\tGetHandleVerifier [0x0x7ff7134bcb29+115657]\n\tGetHandleVerifier [0x0x7ff7134a3268+11016]\n\tBaseThreadInitThunk [0x0x7ffb3edae8d7+23]\n\tRtlUserThreadStart [0x0x7ffb3ffdc34c+44]\n"}} | headers=HTTPHeaderDict({'Content-Length': '987', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
Finished Request
Message: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=139.0.7258.155)
Stacktrace:
        GetHandleVerifier [0x0x7ff7134b3d85+79397]
        GetHandleVerifier [0x0x7ff7134b3de0+79488]
        (No symbol) [0x0x7ff71325c0fa]
        (No symbol) [0x0x7ff713234601]
        (No symbol) [0x0x7ff7132e257e]
        (No symbol) [0x0x7ff713302c72]
        (No symbol) [0x0x7ff7132daf73]
        (No symbol) [0x0x7ff7132a41b1]
        (No symbol) [0x0x7ff7132a4f43]
        GetHandleVerifier [0x0x7ff71377e1ed+3005069]
        GetHandleVerifier [0x0x7ff71377831d+2980797]
        GetHandleVerifier [0x0x7ff713797e0d+3110573]
        GetHandleVerifier [0x0x7ff7134cd6de+184190]
        GetHandleVerifier [0x0x7ff7134d516f+215567]
        GetHandleVerifier [0x0x7ff7134bc974+115220]
        GetHandleVerifier [0x0x7ff7134bcb29+115657]
        GetHandleVerifier [0x0x7ff7134a3268+11016]
        BaseThreadInitThunk [0x0x7ffb3edae8d7+23]
        RtlUserThreadStart [0x0x7ffb3ffdc34c+44]

ℹ️ Last known working version: 4.34.2 or earlier

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions