Webdriver Exception:Process unexpectedly closed with status: 1
Asked Answered
M

3

58

I try to run a selenium program on a Linux machine.But I got the exceptions:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__
    keep_alive=True)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
     File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1

How can I fix the exceptions? Thanks for helping.

Mcdonough answered 18/10, 2017 at 11:29 Comment(2)
What do you mean by fix the exceptions? Share your codePyrognostics
Please read How to Ask, especially the part about minimal reproducible example (MCVE), and How much research effort is expected? This will help you debug your own programs and solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and the execution result including any error messages so we can better help you. Also provide a link to the page and/or the relevant HTML.Mikol
A
128

This error can come up when you are trying to run the browser in non-headless mode on a box that doesn't have a display (like an Ubuntu server).

You can check if that's the cause of your Process unexpectedly closed with status: 1 error by looking at the geckodriver.log file that is usually left in your working directory after you run your script, it should have a line like:

Error: GDK_BACKEND does not match available displays

If you see that line in the geckodriver.log then you'll need to switch your script to run Firefox in headless mode:

from selenium import webdriver
from selenium.webdriver import FirefoxOptions

opts = FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(options=opts)

browser.get('http://example.com')
Ancheta answered 4/12, 2017 at 21:42 Comment(9)
you were spot onAllistir
Can we have a approach using with closing(webdriver.Firefox(firefox_options=opts)) as browser::Steerage
I am using ubuntu desktop and I have a display but when I run the script from CRONTAB the error appears. Switching to headless mode fixes the issue and makes more sense of course.Personalism
Encountered this on google colab, apt-get install all seemed fine. But still got the same error with --headless option.Orphrey
browser = webdriver.Firefox(firefox_options=opts) - there is no firefox_options kwargs. I had to use options insteadFreewill
@Freewill yup, looks like it was removed in 2020: github.com/SeleniumHQ/selenium/commit/… so I've updated the answer. Thanks!Ancheta
Bang on. I'm using Watir and had to pass headless: true as an option when launching a new browser. Thank you for the quick fix!Tan
I still get selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. with just the options and selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1 if I include options and service.Aubreyaubrie
I'm currently running in headless mode in github actions and have not touched the options.add_argument("--headless") and also added options.headless = True but I'm still getting the same error selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1Forefinger
M
4

It's hard to be sure without more information, but this typically happens when the browser version you use is not compatible with the underlying webdriver you use.

Make sure that they are compatible, for example by upgrading your webdriver, and this issue should be solved.

Mady answered 18/10, 2017 at 12:30 Comment(2)
how do you upgrade your webdriver?Helico
@Akin Hwan pypi.org/project/webdriver-managerCrankshaft
A
0

To me this seems like a problem with the Firefox WebDriver. I tested the Chrome driver and driver manager (on Selenium 4.x), and I find that they work. However, the service is buggy so stick to paths. That is, use the driver manager without spawning a service. Explicitly state "executable_path" option else you will encounter the "paths are deprecated" error.

Aubreyaubrie answered 11/4, 2023 at 0:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.