Search code examples
python-3.xseleniumdeprecation-warning

pycharm selenium - deprecation fix


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

Solution

  • 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.