Home >Backend Development >Python Tutorial >How to Fix the Selenium Python DeprecationWarning for `executable_path`?
DeprecationWarning: executable_path is Obsolete in Selenium Python
In Selenium Python, the executable_path argument has been marked as deprecated, prompting a warning message when trying to instantiate a webdriver instance. To resolve this issue, use a Service object instead.
This deprecation is aligned with the release of Selenium 4.0 Beta 1, which states that all arguments except Options and Service will be deprecated.
Solution
To fix this bug and ensure compatibility with Selenium v4, follow these steps:
Ensure Selenium is upgraded to v4.0.0:
pip3 install -U selenium
Install Webdriver Manager for Python:
pip3 install webdriver-manager
Use the following updated code block (assuming Chrome):
from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) driver.get("https://www.google.com")
If you wish to pass Options arguments:
from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("start-maximized") driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) driver.get("https://www.google.com")
This workaround should eliminate the deprecation warning and provide seamless WebDriver usage with Selenium v4.
For further details, consult the Selenium 4.0 changelog, bug report, and pull request:
The above is the detailed content of How to Fix the Selenium Python DeprecationWarning for `executable_path`?. For more information, please follow other related articles on the PHP Chinese website!