Dead_Light
Dead_Light

Reputation: 27

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

Although I know my question might be similar to some others, I have a serious problem with this, i get Message: invalid argument: can't kill an exited process in error while trying to run the code. Note that I run this on ubuntu 20 and it doesn't have display.

Here is my code:


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=options)


Error in console

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

And this is the geckodriver log file:

1603574335551   geckodriver INFO    Listening on 127.0.0.1:59603
1603574336562   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenqjQeL"
Error: no DISPLAY environment variable specified

I also read about the incompatibility of versions but it seems all of them are compatible:

I appreciate any help and how may I fix it?

Upvotes: 1

Views: 547

Answers (1)

Dead_Light
Dead_Light

Reputation: 27

After searching for hours and wasting a day, finally, I understood that you have to do these things:

First that, you have to open webdriver in headless mode, but not like what I did above, like this:

from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument('-headless')
driver = webdriver.Firefox(executable_path='path', options=options)

Also make sure that your geckodriver is executable in ubuntu, using this command:

sudo chmod +x geckodriver

It should fix the problem for newer versions of selenium and firefox and geckodriver.

Upvotes: 1

Related Questions