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:
chrome_options.binary_location
: The parameter points to the chrome.exe not the chromedriver.exeos.path.abspath("chromedriver")
will pick up the file path of chromedriver but won't append chromedriver.exe at the end.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
Convert List of Dictionaries to a Pandas Dataframe
How to Read and Write CSV Files With Python
Loop "Forgets" to Remove Some Items
Pygame Window Not Responding After a Few Seconds
Split a String by a Delimiter in Python
What Is the Syntax Rule For Having Trailing Commas in Tuple Definitions
Updating Gui Elements in Multithreaded Pyqt
Numpy 'Logical_Or' For More Than Two Arguments
Basic Query Regarding Bindtags in Tkinter
Difference Between Null=True and Blank=True in Django
Difference Between Range and Xrange Functions in Python 2.X
How to Read a Text File into a String Variable and Strip Newlines
Iterating Through a Range of Dates in Python
How to Read Large Text Files Line by Line, Without Loading It into Memory