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

Time:11-11

I started a selenium tutorial today and have run into this error when trying to run the code. I've tried other methods but ultimately get the same error. I'm on MacOS using VSC.

My Code:

from selenium import webdriver

PATH = '/Users/blutch/Documents/Chrom Web Driver\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get("https://www.google.com")

I've also tried inserting C: in front of /Users. Can anyone guide me on why this is happening/how to fix it?

CodePudding user response:

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:

  • Related