0
0
Selenium-pythonDebug / FixBeginner · 4 min read

How to Fix WebDriver Not Found Error in Selenium

The 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.

python
from selenium import webdriver

# Broken code: No driver path specified
browser = webdriver.Chrome()
browser.get('https://example.com')
Output
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
🔧

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.

python
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')
Output
Browser opens https://example.com without errors
🛡️

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 +x on the driver file.

Key Takeaways

Download and use the correct browser driver for your Selenium tests.
Specify the driver path explicitly or add it to your system PATH.
Keep drivers updated to match your browser version.
Use tools like WebDriver Manager to automate driver management.
Check file permissions if driver execution fails.