Selenium WebDriver TypeError: "executable_path" Argument
Encountering TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable_path'
in Selenium indicates a breaking change in how WebDrivers are initialized. This error arises because modern Selenium versions deprecated this parameter.
Why This Error Occurs
Starting with Selenium v4.10.0
(released mid-2023), the executable_path
argument was removed from WebDriver.__init__()
. The change aims to standardize driver management through the Service
class.
WARNING
If using Selenium ≥4.6.0, executable_path
is obsolete. Solutions below apply to version 4.10.0+.
Recommended Solutions
1. Use Service
for Explicit Driver Path
Replace executable_path
with a Service
instance:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
service = Service(executable_path='./chromedriver.exe') # Specify driver path
options = Options()
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://www.google.com/')
driver.quit() # Always clean up resources
2. Automate Driver Management (No Manual Path)
For Selenium ≥4.6.0, omit executable_path
entirely. Selenium Manager automatically handles driver binaries:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
driver = webdriver.Chrome(options=options) # Simplified initialization
driver.get('https://www.google.com/')
driver.quit()
TIP
Selenium Manager downloads/uses the correct driver version for your browser, provided it's installed system-wide.
3. Use webdriver_manager
for Dynamic Driver Handling
Install the package to avoid manual driver downloads:
pip install webdriver-manager
Then initialize:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(
service=ChromeService(ChromeDriverManager().install()),
options=options
)
driver.get('https://www.google.com/')
driver.quit()
Key Takeaways
- Deprecation Rationale: Selenium replaced
executable_path
with dependency-injectableService
objects for better resource management. - Best Practice: Use automatic driver management (Solution #2) unless explicit path control is necessary.
- Compatibility: Solutions apply to Chromium-based browsers (Chrome, Edge). For Firefox, use
FirefoxService
fromselenium.webdriver.firefox.service
.
Avoid Outdated Patterns
Do not downgrade Selenium! Explicit paths increase maintainability issues. Modern workflows avoid hardcoded executable_path
.
Adopting these patterns ensures compatibility with modern Selenium ecosystem changes.