Home > Article > Backend Development > Why Am I Getting a WebDriverException: \'chromedriver\' Executable Not Found in Selenium?
WebDriverException: 'chromedriver' Executable Not Found
Selenium's WebDriverException is a common error when working with Chromedriver. This error occurs when the 'chromedriver' executable is not present in the system's PATH environment variable.
Analyzing the Error
The error is thrown in this specific case because an attempt is being made to modify the user agent using Selenium Chromedriver in Python. The following lines of code are used:
from selenium import webdriver chrome_path = r'C:\Users\Desktop\chromedriver_win32\chromedriver.exe' driver = webdriver.Chrome(chrome_path) 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)
However, the error persists despite setting the correct path for the chromedriver executable.
Solution
The solution to this issue is to pass the 'executable_path' along with the absolute path of the chromedriver executable while initializing the WebDriver. This is done 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')
By providing the 'executable_path' parameter, the WebDriver is directed to the specific location of the chromedriver executable, resolving the error.
The above is the detailed content of Why Am I Getting a WebDriverException: \'chromedriver\' Executable Not Found in Selenium?. For more information, please follow other related articles on the PHP Chinese website!