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

invalid argument: can’t kill an exited process with Selenium, GeckoDriver and Python on RaspberryPi3 is an error which occurs when you are not running in headless mode.

In this article I am going to explain why the error is happening and how to run Selenium without getting the error again. Also we are going to check out other solutions that may work for your particular case.

Explaining the Error invalid argument: can’t kill an exited process with Selenium, GeckoDriver and Python on RaspberryPi3

In most cases The error is occurring because you are not running in headless mode. But first let us reproduce the error and see the error message.

This is how the error message looks like.

                                                                       #
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)
....
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
                                                                       #

You can reproduce the error by using these two sections in your code. First, we start with the imports.

                                                                       #
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
                                                                       #

Then, the actual code.

                                                                       #
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)

print('Need your login credential')
username = input('Enter the username?:\n')
password = input('Enter the password?:\n')
                                                                       #

Bellow we will take care of the error using multiple possible solutions according to your needs.

Solution 1 : run in headless mode.

In this example, the first reason this error occurs is that Raspberrypi is a device that has no screen, so you need to run selenium in headless mode. This example uses Firefox, maybe you have another browser, so make sure to use headless mode.

You can achieve this with the code bellow. First, we must start with the imports.

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

Then, we add the actual code

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

I hope this solution worked for you, we have another one bellow.

Solution 2 : Installing firefox, The Firefox.

This may sound weird, but for a lot of people, just installing Firefox on the device fixed the issue.

Im not talking about python, Im talking about the actuall firefox browser.

So head to the firefox website and download their browser and then install it on your device and see if the error persists.

Solution 3 : Solve compatibility issues.

Another cause of the problem, is not the absence of the headless mode but it is the incompatibility between te versions of Firefox, geodriver and selenium.

You need to check out the compatibility chart of Firefox, geodriver and selenium.

You can do that by following this official link.

https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/Support.html

Install the appropriate versions and see if the error is gone.

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up

I hope this article has been helpful and helped you solve this error, the first solution should be enough and should work for Windows and Linux.

I hope you continue coding and learning Python, errors are part of the fun even when we hate them, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/