WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium and Python on RaspberryPi3

71,229

Solution 1

Thumb rule

A common cause for Browsers to crash during startup is running WebDriver initiated Browsers as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Browser as a regular user instead.


This error message...

selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • Your GeckoDriver version is 0.22.0.

  • Release Notes of GeckoDriver v0.21.0 (2018-06-15) clearly mentions the following:

  • Firefox 57 (and greater)

  • Selenium 3.11 (and greater)

  • Your Firefox version is 52.9.0.

So there is a clear mismatch between GeckoDriver v0.22.0 and the Firefox Browser v57


Solution

  • Upgrade GeckoDriver to GeckoDriver v0.22.0 level.
  • GeckoDriver is present in the specified location.
  • GeckoDriver is having executable permission for non-root users.
  • Upgrade Firefox version to Firefox v62.0.2 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Execute your Selenium Test as a non-root user.

GeckoDriver, Selenium and Firefox Browser compatibility chart

geckodriver_versions

Solution 2

If you are running Firefox on a system with no display, make sure you use headless mode.

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

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

Also, make sure you have compatible versions of Firefox, Selenium, and Geckodriver: https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

Solution 3

I was on headless mode, using correct versions of everything, and the only way to get out of this error message was not to execute the selenium test as root

Solution 4

Yes checked Start Xvfb before the build can fix the problem, but if you have a job like a pipeline or multibranch pipeline this option is not visible. In the node of your Selenium grid that you go to execute the test you need:

1- Install Xvfb: apt install xvfb

2- Execute Xvfb: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"

3- Rerun your node, for example: java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991

Solution 5

This solution worked for me

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

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Share:
71,229
Chokoladekiks
Author by

Chokoladekiks

Updated on July 09, 2022

Comments

  • Chokoladekiks
    Chokoladekiks almost 2 years

    Server: Raspberry Pi 3
    OS: Dietpi - version 159
    Geckodriver version: 0.22 for arm
    Firefox version: 52.9.0
    Python version: 3.5
    Selenium version: 3.14.1

    Gecko is executable, and is located in /usr/local/bin/

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.firefox.options import Options
    import time
    
    
    
    options = Options()
    options.set_headless(headless=True)
    driver = webdriver.Firefox(firefox_options=options)
    
    print('Need your login credential')
    username = input('What is your username?:\n')
    password = input('What is your password?:\n')
    ...
    ...
    

    Output:

    root@RPi3:~# python3.5 ITE-bot.py 
    Traceback (most recent call last):
      File "ITE-bot.py", line 12, in <module>
        driver = webdriver.Firefox(firefox_options=options)
      File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
        keep_alive=True)
      File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
        self.start_session(capabilities, browser_profile)
      File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
        response = self.execute(Command.NEW_SESSION, parameters)
      File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
    

    Any idea what is wrong? I've tried google without luck.

  • carlin.scott
    carlin.scott over 5 years
    xvfb isn't needed due to running the browser in headless mode.
  • tyrex
    tyrex about 5 years
    thanks, this worked for me when having similar problem, on a server running ubuntu 16.04
  • Nicolás Ozimica
    Nicolás Ozimica about 5 years
    It worked for me too. It is important to remark that firefox itself must be installed in the system. At least for me, this code above worked only after installing firefox.
  • akostadinov
    akostadinov almost 5 years
    Running as root, I didn't think can be a problem. It was, thanks. When I was setting custom capabilities the error was different although with same root cause. Pasting here for anybody searching: Unable to find a matching set of capabilities (Selenium::WebDriver::Error::SessionNotCreatedError)
  • Alex Povel
    Alex Povel over 4 years
    Running it from the terminal (outside of VSCode) also solved it for me, running Firefox 68.0.1., Selenium 3.141.0 and geckodriver v0.24.0. That setup is compatible and then actually works after invoking it from the regular terminal (even without headless).
  • Matrix
    Matrix over 4 years
    how restart (kill actual) and start /usr/bin/Xvfb ?
  • Eric Ihli
    Eric Ihli over 4 years
    Just to give people out there more information in case it helps: I am running a process as root and it is working. My problem was that I was needed to run with the headless option.
  • Ryan Farrell
    Ryan Farrell over 4 years
    I updated everything to its newest version, geckodriver is in the correct location on my computer (running ubuntu 19.04) and I am still getting the same error message as in the original question. Not sure what do to now
  • gaurav kumar
    gaurav kumar about 4 years
    I am using a docker selenium grid, with image : selenium/node-firefox-debug:3.141.59 . It shows that it has the compatible versions. But still i am facing above errors.
  • the.Legend
    the.Legend about 4 years
    That should be top answer - Firefox won't run outside of X session, so if anyone's running via docker or ssh make sure to start Xvfb to emulate it
  • iarp
    iarp about 4 years
    If you're getting the WebDriverException error and you have the most updated versions of firefox and geckdriver AND you're on a headless machine, you need to set headless = True as Anar has mentioned here.
  • Manish Kumar
    Manish Kumar almost 4 years
    @DebanjanB In Robot framework Installed python 3.6.9, Firefox 77.0.1 and geckodriver 0.26.0 in ubuntu 18.04 getting error as WebDriverException: Message: invalid argument: can't kill an exited process Can you please help?
  • Admin
    Admin over 3 years
    I encounter this error somewhat randomly when running Firefox under a standalone selenium server. Restarting the selenium server appears to resolve (MacOS)
  • Morten Engelsmann
    Morten Engelsmann over 3 years
    Changing process owner worked for me: I moved from inside the Visual Studio Code to the OS built-in terminal. Although I am not capable of identifying process owner in my Linux system, I solved the problem, using the WebDriver method call driver = webdriver.Firefox(firefox_binary='/path/to/firefox'). I got multiple exceptions from inside VSC (depending on which tricks I tried, running the script either from a terminal $ python mytest.py or in Debugging mode from the editor.
  • Morten Engelsmann
    Morten Engelsmann over 3 years
    One problem I had was that the ESR version of Firefox was included in my distro, and it gave me problems. I thus downloaded and unzipped a non-ESR version, and had to manage with dual Firefox installation.
  • Eric Ihli
    Eric Ihli over 3 years
    This is the exact troubleshooting step I took to resolve the issue. Error: cannot open display: :0.0 is the message I saw in the logs. The environment variable DISPLAY in my Python process was trying to use display :0.0, which didn't exist. Changing that env var to the correct display was the fix.