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:
chrome_options.binary_location
: The parameter configures thechrome.exe
not thechromedriver.exe
os.path.abspath("chromedriver")
will pick up the file path ofchromedriver
but won't appendchromedriver.exe
at the end.Here is the sample code on my
Windows 8
system to startChrome
inHeadless 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")