How to Fix WebDriver Not Found Error in Selenium
webdriver not found error in Selenium happens when the browser driver executable is missing or not properly linked. Fix it by downloading the correct driver for your browser and setting its path correctly in your code or system environment variables.Why This Happens
This error occurs because Selenium needs a browser-specific driver to control the browser, such as ChromeDriver for Chrome or GeckoDriver for Firefox. If Selenium cannot find this driver executable, it throws a 'webdriver not found' error.
Common causes include missing driver files, incorrect driver paths, or not setting the driver path in the system environment.
from selenium import webdriver # Broken code: No driver path specified browser = webdriver.Chrome() browser.get('https://example.com')
The Fix
Download the correct driver for your browser version from the official site (e.g., ChromeDriver for Chrome). Then, specify the driver path explicitly in your code or add it to your system PATH environment variable.
This tells Selenium where to find the driver executable so it can launch the browser.
from selenium import webdriver from selenium.webdriver.chrome.service import Service # Fixed code: Specify the path to the ChromeDriver executable service = Service('/path/to/chromedriver') browser = webdriver.Chrome(service=service) browser.get('https://example.com')
Prevention
Always keep your browser driver updated to match your browser version. Use tools like WebDriver Manager to automate driver downloads and path setup.
Set environment variables properly so you don’t have to hardcode paths. Regularly test your setup after browser updates to avoid surprises.
Related Errors
- SessionNotCreatedException: Happens if driver version and browser version mismatch. Fix by updating driver.
- Permission Denied: Driver file lacks execute permission. Fix by changing file permissions.
- Driver executable is not executable: On Unix systems, fix by running
chmod +xon the driver file.