Selenium.Common.Exceptions.Webdriverexception: Message: 'Chromedriver' Executable Needs to Be in Path Error With Headless Chrome

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome

If we analyze the logs it seems the main issue is with in start os.path.basename(self.path) and subsequent error message:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

So it's clear from the error that the Python client was unable to locate the chromedriver executable binary.

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

  1. chrome_options.binary_location : The parameter points to the chrome.exe not the chromedriver.exe

  2. os.path.abspath("chromedriver") will pick up the file path of chromedriver but won't append chromedriver.exe at the end.

  3. Here is the sample code on my windows-8 system to start google-chrome-headless:

    from selenium import webdriver  
    from selenium.webdriver.chrome.options import Options

    chrome_options = Options()
    chrome_options.add_argument("--headless")
    driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("http://www.duo.com")
    print("Chrome Browser Initialized in Headless Mode")
    driver.quit()
    print("Driver Exited")

Error chromedriver executable needs to be in PATH

In the self.driver = webdriver.Chrome(), pass the path to the executable as an argument in the parentheses.

For example:

self.driver = webdriver.Chrome('C:/user/Downloads/chromedriver.exe')

Executable path needs to be in PATH in Python

try this

webdriver.Chrome(executable_path= r"C:\\Users\\LENOVO\\AppData\\Local\\Programs\\Python\\Python38-32\\chromedriver.exe")

And make sure you have chrome driver there

or it will still show up this error

Traceback (most recent call last): File "C:/Users/LENOVO/Desktop/Coding -Winson/PyCharm/opening_webs.py", line 3, in driver = webdriver.Chrome('/path/to/chromedriver') File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init self.service.start() File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\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://sites.google.com/a/chromium.org/chromedriver/home

If the problem still persists try putting a copy of chrome executable in the current path where your python program is located

Error message: 'chromedriver' executable needs to be available in the path

You can test if it actually is in the PATH, if you open a cmd and type in chromedriver (assuming your chromedriver executable is still named like this) and hit Enter. If Starting ChromeDriver 2.15.322448 is appearing, the PATH is set appropriately and there is something else going wrong.

Alternatively you can use a direct path to the chromedriver like this:

 driver = webdriver.Chrome('/path/to/chromedriver') 

So in your specific case:

 driver = webdriver.Chrome("C:/Users/michael/Downloads/chromedriver_win32/chromedriver.exe")


Related Topics



Leave a reply



Submit