Home > database >  pycharm selenium - deprecation fix
pycharm selenium - deprecation fix

Time:08-21

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()
~~~

CodePudding user response:

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"

CodePudding user response:

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