DeprecationWarning: executable_path has been deprecated selenium python
I could figure it out
# pip install webdriver-manager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
s=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('https://www.google.com')
driver.find_element(By.NAME, 'q').send_keys('Yasser Khalil')
This works for me
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
ser = Service("C:\\chromedriver.exe")
op = webdriver.ChromeOptions()
s = webdriver.Chrome(service=ser, options=op)
This error message...
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
...implies that the key executable_path
will be deprecated in the upcoming releases.
This change is inline with the Selenium 4.0 Beta 1 changelog which mentions:
Deprecate all but
Options
andService
arguments in driver instantiation. (#9125,#9128)
Solution
With selenium4 as the key executable_path
is deprecated you have to use an instance of the Service()
class along with ChromeDriverManager().install()
command as discussed below.
Pre-requisites
Ensure that:
-
Selenium is upgraded to v4.0.0
pip3 install -U selenium
-
Webdriver Manager for Python is installed
pip3 install webdriver_manager
You can find a detailed discussion on installing Webdriver Manager for Python in ModuleNotFoundError: No module named 'webdriver_manager' error even after installing webdrivermanager
Selenium v4 compatible Code Block
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")
Console Output:
[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 96.0.4664
[WDM] - Get LATEST driver version for 96.0.4664
[WDM] - Driver [C:\Users\Admin\.wdm\drivers\chromedriver\win32\96.0.4664.45\chromedriver.exe] found in cache
You can find a detailed discussion on installing Webdriver Manager for Python in Selenium ChromeDriver issue using Webdriver Manager for Python
Incase you want to pass the Options()
object you can use:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")
TL; DR
You can find the relevant Bug Report/Pull Request in:
- Bug Report: deprecate all but Options and Service arguments in driver instantiation
- Pull Request: deprecate all but Options and Service arguments in driver instantiation