0

Okay so I'm new to pycharm and selenium my issue is

initially the issue was a error for unicode but I figured out how to get past it in python I would just use \\ instead of \ in pycharm I had to put "r" in the file path (r"c:/blahblah). however now I'm seeing

DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(r"C:\Users\BatMan\PycharmProjects\DellUpdate\Drivers\chromedriver.exe")

I did find out that deprecation is the end of life of a module in a future minor/major update. Is there something I could or should do prior to the update? or how will I know what the new fix is that replaces the "r" in front of the file path?

from selenium import webdriver

driver = webdriver.Chrome(r"C:\Users\BatMan\PycharmProjects\DellUpdate\Drivers\chromedriver.exe")
driver.get("https://www.dell.com/support")
driver.maximize_window()
~~~
Navi Kzc
  • 19
  • 2
  • 8

2 Answers2

2

Your question is very close to DeprecationWarning: executable_path has been deprecated selenium python

The executable_path parameter was deprecated, and now you need to create a Service object and pass it to the Chrome constructor.

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

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

This has nothing to do with "r"

1

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.

Anand Gautam
  • 2,018
  • 1
  • 3
  • 8
  • It worked! Can you help me understand a bit better what that's doing/ when to know to use this in the future? – Navi Kzc Aug 20 '22 at 14:13
  • 2
    `Service` is a class in Selenium, and you are creating a service object, and the main argument it requires is the `executable_path`. As far as I know, `executable_path` which existed before has been wrapped into a class now called `Service`. I do not know mucn intrinsic details on it, but if you create an object like this and use, you wouldn't get the deprecation warning. Essentially service object does the same as executable_path. It enables your code to invoke the webdriver from the set path. – Anand Gautam Aug 20 '22 at 14:24