Search code examples
pythongoogle-chromeselenium-webdriverselenium-chromedriverseleniummanager

Selenium 4.11.2 with ChromeDriver and Chrome


I'm trying to run this simple code.. But I get a error that I can not fix. Can someone help me ?

Chrome driver is installed I check:

pi@Rpi:~ $ chromedriver --version
ChromeDriver 92.0.4515.98 (564abd8de2c05f45308eec14f9110a10aff40ad9-refs/branch-heads/4515@{#1501})

Code:

from selenium import webdriver

driver=webdriver.Chrome()
driver.get("https://www.google.com/")

Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/selenium_manager.py", line 123, in run
    completed_proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/lib/python3.7/subprocess.py", line 472, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/linux/selenium-manager'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/selenium_manager.py", line 90, in driver_location
    output = self.run(args)
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/selenium_manager.py", line 129, in run
    raise WebDriverException(f"Unsuccessful command executed: {command}") from err
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: /usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/linux/selenium-manager --browser chrome --output json


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/pi/src/test.py", line 3, in <module>
    driver=webdriver.Chrome()
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 50, in __init__
    keep_alive,
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/chromium/webdriver.py", line 51, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

I tried reinstalling selenium couple of times. I also tried reinstalling webdriver. Tried to locate the path. But I read it is not necessary anymore. I put the Chromedriver in the Same directory as the Python project

Snapshot of project + Chromedriver:

Place of project + Chromedrive


Solution

  • I put the Chromedriver in the Same directory as the Python project

    As you are using Selenium v4.11.2 you don't need to explicitly download ChromeDriver, GeckoDriver or any browser drivers or even need use webdriver_manager any more. You just need to ensure that the desired browser client i.e. , or is installed.


    Selenium Manager

    Selenium Manager is the new tool integrated with that would help to get a working environment to run Selenium out of the box. Beta 1 of Selenium Manager will configure the browser drivers for Chrome, Firefox, Edge, etc, browser clients, if they are not present on the PATH.


    Solution

    As a solution you can simply do:

    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.get("https://www.google.com/")
    

    tl; dr

    Chrome for Testing: reliable downloads for browser automation