WebDriver init() multiple values for 'options'
Problem Statement
When initializing a Chrome WebDriver in Selenium Python with explicit driver executable paths and browser options
, you might encounter the error:TypeError: WebDriver.__init__() got multiple values for argument 'options'
.
This error frequently occurs in Selenium 4.10.0
and newer versions due to API changes where the constructor signature no longer accepts executable_path
as a positional argument. Instead, it expects options
as the first argument.
Example code causing the error:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# Triggers error: executable_path now conflicts with options
browser = webdriver.Chrome(
executable_path=r'/usr/bin/chromedriver', # Problematic position
options=chrome_options
)
Error traceback:
TypeError: WebDriver.__init__() got multiple values for argument 'options'
Solutions
Follow these approaches to resolve the conflict, depending on your use case.
1. Use Service Object (Recommended)
Selenium ≥4.10.0 requires using a Service
object to specify the driver path. This is the official solution that works across all environments.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
# Configuration
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
service = Service(executable_path=r'/usr/bin/chromedriver') # Path to chromedriver
driver = webdriver.Chrome(
service=service, # Pass service instead of executable_path
options=chrome_options
)
# ... your code ...
driver.quit() # Clean up resources
2. Automatic Driver Management (No Explicit Path)
If you don't need explicit driver path management, chromedriver_autoinstaller
simplifies setup by auto-downloading the correct driver version.
# Install helper library
!pip install chromedriver-autoinstaller # For notebooks; omit '!' in regular scripts
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_autoinstaller
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# Auto-installs and configures chromedriver
chromedriver_autoinstaller.install()
driver = webdriver.Chrome(options=chrome_options)
# ... your code ...
driver.quit()
Explanation
API CHANGES IN SELENIUM 4.10.0
Prior to Selenium 4.10.0, webdriver.Chrome()
accepted executable_path
as the first positional argument. Newer versions interpret the first argument as options
, causing a conflict when both positional executable_path
and keyword options
are passed.
Why the error occurs:
The current Chrome WebDriver constructor expects either:- A positional
options
argument OR - Keyword arguments including
service
andoptions
.
Passing both a positional argument (mistaken asoptions
) and an explicitoptions
keyword creates duplication.
- A positional
Solution 1 advantages:
- Maintains explicit driver path control
- Follows Selenium's updated best practices
- Works in persistent environments (e.g., servers, containers)
Solution 2 advantages:
- Simplifies driver setup
- Ideal for ephemeral environments (e.g., Google Colab, CI/CD pipelines)
- Automatically handles driver version compatibility
CHECK YOUR SELENIUM VERSION
Verify your Selenium version with pip show selenium
. Solutions apply to 4.10.0+. Downgrading to older versions (e.g., pip install selenium==4.9.0
) is not recommended as it avoids modern best practices and security updates.
Conclusion
Use the Service
object to pass the driver path explicitly or adopt chromedriver_autoinstaller
for simplified workflows. Both solutions eliminate the multiple values for argument 'options'
error while aligning with current Selenium practices. Always prefer Selenium's Service
API for long-term compatibility.