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 binary.

You have to take care of a couple of points here:

  1. chrome_options.binary_location : The parameter configures 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 Chrome in Headless Mode:

    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")
    

Leave a Comment