[Python] "not connected to DevTools", how can I handle this in selenium, python3?

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    Today, I really do my first time at selenium. but, I can't step forward.

    first, I run below code

    from selenium import webdriver
    import time

    driver = webdriver.Chrome()
    driver.get('https://www.google.com/')
    time.sleep(3)


    and got error like this

    ...
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
    (session not created: DevToolsActivePort file doesn't exist)
    (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    Stacktrace:
    #0 0x5617c37fd10a <unknown>
    #1 0x5617c34e35e0 <unknown>
    #2 0x5617c351b921 <unknown>
    #3 0x5617c35172c5 <unknown>
    #4 0x5617c3563df6 <unknown>
    #5 0x5617c3563446 <unknown>
    #6 0x5617c35578c3 <unknown>
    #7 0x5617c35256b3 <unknown>
    #8 0x5617c352668e <unknown>
    #9 0x5617c37c7b0b <unknown>
    #10 0x5617c37cba91 <unknown>
    #11 0x5617c37b4305 <unknown>
    #12 0x5617c37cc612 <unknown>
    #13 0x5617c379946f <unknown>
    #14 0x5617c37ec008 <unknown>
    #15 0x5617c37ec1d3 <unknown>
    #16 0x5617c37fbf5c <unknown>
    #17 0x7f1f507ad609 start_thread


    So I google this error and try this

    from selenium import webdriver
    import time

    chrome_options=webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument("--single-process")
    chrome_options.add_argument("--disable-dev-shm-usage")

    driver = webdriver.Chrome(options=chrome_options)
    driver.get('https://www.google.com/')
    time.sleep(3)


    and got error

    ...
    selenium.common.exceptions.WebDriverException: Message: disconnected: Unable to receive message from renderer
    (failed to check if window was closed: disconnected: not connected to DevTools)
    (Session info: chrome=129.0.6668.70)
    ...


    I can't find same error like this.

    version selenium: 4.25.0 Google Chrome 129.0.6668.70 ChromeDriver 129.0.6668.70 (df87d5cf12b1397be7495a04cab2db6239b227a8-refs/branch-heads/6668@{#1420})

    Continue reading...

Compartilhe esta Página