[Python] Selenium on Python with Geckdriver crashes when not in headless mode

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

  1. Stack

    Stack Membro Participativo

    I'm trying to use Selenium on a jupyter notebook with geckodriver.

    Although on headless mode it seems to work fine, I need to see the browser window since I'm learning...

    I've checked that both browser and driver are compatibles, driver it's added on the PATH variable and a few more tips I've seen around...

    This works fine:

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options

    options = Options()
    options.headless = True
    driver = webdriver.Firefox(options=options)
    driver.get("http://google.com/")
    print ("Headless Firefox Initialized")
    driver.quit()


    But when removing the headless option, it crashes:


    WebDriverException: Message: invalid argument: can't kill an exited process
    ​

    The only clue I can find its in the geckodriver.log where I can read:


    1596560987355 mozrunner::runner INFO Running command: "/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilejjh45q" Error: no DISPLAY environment variable specified
    ​

    I've checked that that variable exists and it's like DISPLAY:0. I've also tried to change the value, to set it to my ip and port....

    This is driving me a bit mad so if anyone can give my hand it would be awesome!! Thanks in advance!!

    --> Update: as @Wunderbread suggested, SeleniumBase works without problem.

    --> Update: I was working Selenium on Jupiter Hub. Neither works on jupyter tree or PyCharm or VSC, but..... works perfect from a script on the terminal... life has mysteries.... xDD

    Continue reading...

Compartilhe esta Página