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')

Leave a Comment