Deprecationwarning: Executable_Path Has Been Deprecated Selenium Python

DeprecationWarning: executable_path has been deprecated selenium python

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 and Service 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

Selenium executable_path has been deprecated

This error message

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

means that the key executable_path will be deprecated in the upcoming releases.

Once the key executable_path is deprecated you have to use an instance of the Service() class as follows:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

path = (chrome)
s = Service(path)
driver = webdriver.Chrome(service=s)

For more details see here

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

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 and Service arguments in driver instantiation. (#9125,#9128)



Solution

Once the key executable_path is deprecated you have to use an instance of the Service() class as follows:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service('C:/Users/.../chromedriver.exe')
driver = webdriver.Chrome(service=s)


TL; DR

You can find a couple of relevant detailed discussion 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

pycharm selenium - deprecation fix

You need to use this, service object instead of executable_path

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

serv = Service(r"C:\Users\BatMan\PycharmProjects\DellUpdate\Drivers\chromedriver.exe")
driver = webdriver.Chrome(service=serv)
driver.get("https://www.dell.com/support")
driver.maximize_window()

P.S. executable_path would still work for now. It's a deprecation warning, but better use service object, as support for deprecation would be withdrawn in the future.



Related Topics



Leave a reply



Submit