Webdriverexception: Message: 'Chromedriver' Executable Needs to Be in Path While Setting Useragent Through Selenium Chromedriver Python

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



Leave a reply



Submit