Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH using ChromeDriverManager and Python

I tried to fix the above error by check Stackoverflow and other resources from the internet. But I am getting the error.

I have installed the webdriver_manager also. But I could not able to run the code.

I am using kubuntu, pycharm.

Below is my code:

from selenium import webdriver
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

'''from webdriver_manager.chrome import ChromeDriverManager
driver.implicitly_wait(0.5)
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
#driver = webdriver.Chrome(ChromeDriverManager().install())'''

driver = webdriver.Chrome()
#driver = webdriver.Chrome(executable_path="/home/halovivek/Documents/Automation/selenium_driver/chromedriver.exe")
#driver = webdriver.Chrome()"
driver.maximize_window()
driver.get("https://www.google.com")

Below is my error message:

/home/halovivek/PycharmProjects/pythonProject/venv/bin/python /home/halovivek/PycharmProjects/pythonProject/Test.py


====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
Driver [/home/halovivek/.wdm/drivers/chromedriver/linux64/98.0.4758.102/chromedriver] found in cache
/home/halovivek/PycharmProjects/pythonProject/Test.py:4: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(ChromeDriverManager().install())
Traceback (most recent call last):
  File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/halovivek/PycharmProjects/pythonProject/Test.py", line 16, in <module>
    driver = webdriver.Chrome()
  File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in __init__
    self.service.start()
  File "/home/halovivek/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home


Process finished with exit code 1

Please help me to find the solution

like image 636
vivek rajagopalan Avatar asked Oct 19 '25 15:10

vivek rajagopalan


2 Answers

You need to take care of a couple of things as follows:

  • If at all you are using ChromeDriverManager - Webdriver Manager for Python you don't have to explicitly download the ChromeDriver as it automatically gets downloaded.
  • If you want to use the downloaded ChromeDriver you can avoid using ChromeDriverManager - Webdriver Manager
  • Additionally, executable_path has been deprecated in selenium4 and you have to use an instance of Service().

Solution

Using ChromeDriverManager you can use the following code block:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://www.google.com")

Downloading a specific version of ChromeDriver you can use the following code block:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service('/home/halovivek/Documents/Automation/selenium_driver/chromedriver')
driver = webdriver.Chrome(service=s)

Note: If you are on Linux / MAC O SX system you need to strip the extension part i.e. .exe as it is applicable only for windows platforms.


Reference

You can find a couple of detailed discussions in:

  • Use Selenium with Brave Browser pass service object written in python
like image 115
undetected Selenium Avatar answered Oct 21 '25 04:10

undetected Selenium


The error is

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

Solution is:

s = Service('/home/halovivek/Documents/Automation/selenium_driver/chromedriver.exe')
driver = webdriver.Chrome(service = s)
driver.maximize_window()
driver.get("https://www.google.com")

Make sure to download latest version of chromedriver from here

Imports:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
like image 28
cruisepandey Avatar answered Oct 21 '25 03:10

cruisepandey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!