Selenium 4 and webdriver manager for firefox fails to run in Ubuntu

3.6k Views Asked by At

Apologies I am quite new to all this so trying to figure out if I am doing the right thing. I am running Ubuntu 22.04 and Selenium 4.8

I installed latest Geckodriver from Mozilla GitHub, converted it into executable and then moved it to /usr/local/bin/

I then downloaded webdriver manager and tried to run the following snippet for Firefox:

# selenium 4 - updating geckodriver for firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))

When I run that, it starts downloading: [WDM] - Downloading: 19.0kB [00:00, 13.9MB/s] and then it fails I get following error: selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 127

full error:

[WDM] - Downloading: 19.0kB [00:00, 13.9MB/s]                   
Traceback (most recent call last):
  File "/home/gizmo/PycharmProject/PythonProjects/web/firefox_selenium.py", line 6, in <module>
    driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
  File "/home/gizmo/PycharmProject/PythonProjects/venv/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver.py", line 196, in __init__
    super().__init__(command_executor=executor, options=options, keep_alive=True)
  File "/home/gizmo/PycharmProject/PythonProjects/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/gizmo/PycharmProject/PythonProjects/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/gizmo/PycharmProject/PythonProjects/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/home/gizmo/PycharmProject/PythonProjects/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 127

Where am I going wrong?

Goal: tried to get the webdriver manager to update my geckodriver for Firefox - ran it as a test to see if it is all setup correctly.

1

There are 1 best solutions below

13
undetected Selenium On

Pre-requisites

Ensure that:

  • Selenium is upgraded to v4.0.0 or above

    pip3 install -U selenium
    
  • Webdriver Manager for Python is installed

    pip3 install webdriver-manager
    

You can find a detailed discussion on installing Webdriver Manager for Python in ModuleNotFoundError: No module named 'webdriver_manager' error even after installing webdrivermanager


You don't have to cast to FirefoxService instance and can use the Service instance. You can use:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))

Note: Ensure that your is updated to the latest version.