[Python] Selenium does not work (error) when running via nohup on the server

Discussão em 'Python' iniciado por Stack, Abril 25, 2025.

  1. Stack

    Stack Membro Participativo

    When I run the script on a local PC, everything works, but when I run the script on the server (nohup), errors. The driver version is the same as the program version. python3.10

    Errors:

    NoSuchWindowException: Message: no such window: target window already closed from unknown error: web view not found (Session info: chrome=110.0.5481.100)`
    or WebDriverException: Message: disconnected: Unable to receive message from renderer (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: headless chrome=110.0.5481.100)


    When trying driver.window_handles (to find out how many windows), another error:

    selenium.common.exceptions.WebDriverException: Message: disconnected: not connected to DevTools (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=110.0.5481.100).


    Maybe someone has encountered or knows what the problem is?

    Code:

    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('disable-infobars')
    options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36")
    loc = os.getcwd()
    serv = Service("%s/chromedriver" % loc)
    os.chmod("%s/chromedriver" % loc, 755) driver: webdriver.Chrome = webdriver.Chrome(options=options, service=serv) driver.get("any_link")

    Continue reading...

Compartilhe esta Página