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?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Blutch
  • 123
  • 1
  • 1
  • 6
  • Does this answer your question? [DeprecationWarning: executable\_path has been deprecated selenium python](https://stackoverflow.com/questions/64717302/deprecationwarning-executable-path-has-been-deprecated-selenium-python) – Karl Knechtel Sep 22 '22 at 01:11

1 Answers1

32

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    How would the code setup look like then to account for this? – Blutch Nov 10 '21 at 18:39
  • I get this error Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home During handling of the above exception, another exception occurred: File "/Users/blutch/Documents/Python Tutorials/Selenium Tutorial.py", line 5, in driver = webdriver.Chrome(service=s) I'm using the code above and added driver.get(url) command. I also replaced the path with mine. I'm not sure why this is occuring – Blutch Nov 10 '21 at 22:22
  • 1
    @Blutch For _`Message: 'chromedriver.exe' executable needs to be in PATH`_ error, check [this](https://stackoverflow.com/questions/46085270/selenium-common-exceptions-webdriverexception-message-chromedriver-executabl/46089751#46089751), [this](https://stackoverflow.com/questions/50091420/webdriverexception-message-chromedriver-executable-needs-to-be-in-path-while/50094553#50094553) and [this](https://stackoverflow.com/questions/49201281/error-message-chromedriver-executable-needs-to-be-path/49201386#49201386) discussion. – undetected Selenium Nov 10 '21 at 22:25