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")
selenium - chromedriver executable needs to be in PATH
You can download ChromeDriver here:
https://sites.google.com/chromium.org/driver/
Then you have multiple options:
add it to your system
path
put it in the same directory as your python script
specify the location directly via
executable_path
driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')
WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python
This error message...
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
...implies that the ChromeDriver was not found within the locations specified within PATH variable within Environment Variables.
Solution
You need to pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver along with the ChromeOptions object as an argument while initializing the WebDriver and WebBrowser as follows :
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('user-agent = Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Users\Desktop\chromedriver_win32\chromedriver.exe')
driver.get('https://www.google.co.in')
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')
Related Topics
How to Pass a Variable Between Flask Pages
Why Do Python Classes Inherit Object
Which Python Memory Profiler Is Recommended
Can a Variable Number of Arguments Be Passed to a Function
Binning a Column With Python Pandas
Unicodedecodeerror When Reading CSV File in Pandas With Python
Typeerror: Method() Takes 1 Positional Argument But 2 Were Given
How to Overcome "Datetime.Datetime Not Json Serializable"
Should Import Statements Always Be At the Top of a Module
How to Replace Nans by Preceding or Next Values in Pandas Dataframe
How to Clear the Interpreter Console
How to Use Glob() to Find Files Recursively
How to Install Python Packages [Ssl: Tlsv1_Alert_Protocol_Version]
How to Add Hovering Annotations to a Plot
Is There Any Pythonic Way to Combine Two Dicts (Adding Values For Keys That Appear in Both)