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')
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
Related Topics
Pg_Config Executable Not Found
Having Django Serve Downloadable Files
Setting Y-Axis Limit in Matplotlib
How Does Zip(*[Iter(S)]*N) Work in Python
Proper Name for Python * Operator
I Can't Install Pyaudio on Windows? How to Solve "Error: Microsoft Visual C++ 14.0 Is Required."
How to Set Time Limit on Raw_Input
How to Groupby Consecutive Values in Pandas Dataframe
Error: Pandas Hashtable Keyerror
Understanding Dict.Copy() - Shallow or Deep
Beyond Top Level Package Error in Relative Import
Filter Dict to Contain Only Certain Keys
Python Error "Importerror: No Module Named"
Determine Whether Integer Is Between Two Other Integers
Fast Punctuation Removal with Pandas
Convert Pyspark String to Date Format