'Deprecation issues when using Selenium with PyCharm CE

I am trying to run Selenium through PyCharm CE on MacOS, and am attempting to run it with Google Chrome.

However, whenever I run the following:

from selenium import webdriver

browser = webdriver.Chrome("/Users/louiscage/PycharmProjects/SeleniumPractice/chromedriver")

browser.get('https://inventwithpython.com')

This is the result:

/Users/louiscage/PycharmProjects/SeleniumPractice/SeleniumPractice.py:3: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  browser = webdriver.Chrome("/Users/louiscage/PycharmProjects/SeleniumPractice/chromedriver")

I had downloaded the Chromedriver and Geckodriver for Mac64, and placed it in the proper directory for my PyCharm project. But I still can't seem to find a solution to this issue. Any help would be greatly appreciated.



Solution 1:[1]

As what the warning said: please pass in a Service object, so you should do it like this instead:

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

    service = Service("/Users/louiscage/PycharmProjects/SeleniumPractice/chromedriver")
    browser = webdriver.Chrome(service=service)

    browser.get('https://inventwithpython.com')

Pass the executable path on the chrome Service class and put it on a variable service. And then pass it to the webdriver chrome.

Link reference here: Selenium Chrome webdriver service

Solution 2:[2]

This deprecation issue is appearing on Selenium, Pip and Python updates. For that all you have to do is the following:.

Use the following code & pip install all the python libraries

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
s = Service(ChromeDriverManager().install())
browser = webdriver.Chrome(service=s)
browser.get('https://inventwithpython.com')

Solution 3:[3]

The following worked for me in several versions of webdriver.

from selenium.webdriver.chrome.service import Service

CHROME_DRIVER_PATH = "C:\Development\chromedriver.exe"
service = Service(CHROME_DRIVER_PATH)
driver = webdriver.Chrome(service=service)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Partha Singha
Solution 3 Jose Cheble