. Advertisement .
..3..
. Advertisement .
..4..
Python is the best object-oriented programming language that is widely used. It can create software, websites, games, and mobile applications.
“DeprecationWarning: executable_path has been deprecated, please pass in a Service object” is a fairly common problem that every programmer will face. So, what are our options? Everything will be explained to you.
What is DeprecationWarning: executable_path has been deprecated, please pass in a Service object?
The key executable_path
is deprecated in Selenium 4 and instead, we must use an instance of the Service()
class along with the command ChromeDriverManager().install()
.
Below is a simple example to display the issue
from selenium import webdriver
chrome_driver_path = 'C:/Users/itsmycode/Documents/Dev/chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver_path)
url = "https://www.google.com"
driver.get(url)
The output
main.py:3: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(ChromeDriverManager().install())
The Best Approaches For The Problem “DeprecationWarning: executable_path has been deprecated, please pass in a Service object”
Method 1: Use One instance of Service()
Because the executable path is obsolete in this case, you must use an example of the Service() class as shown below.
from selenium import webdriver
PATH = './chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get("https://www.google.com")
This will provide you with a deprecated warning. Hence, just like an example, you must use the Service() class instance rather than an executable path.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service('C:/Users/.../chromedriver.exe')
driver = webdriver.Chrome(service=s)
Your mistake will now be corrected.
Method 2: Before & After
You are using this code.
from selenium import webdriver
chrome_driver_path = 'C:/Users/ssc/ChromeDriver/chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver_path)
url = "https://www.google.com"
driver.get(url)
Now you should change it like this.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s=Service('C:/Users/ssc/ChromeDriver/chromedriver.exe')
browser = webdriver.Chrome(service=s)
url='https://www.google.com'
browser.get(url)
Method 3: Use the special code
The last way is very easy, you need to use this script to solve the issue.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
ser = Service("C:\\chromedriver.exe")
op = webdriver.ChromeOptions()
s = webdriver.Chrome(service=ser, options=op)
Conclusion
Python is well suited to high-level systems. Nonetheless, achievement would be marginally inadequate to native language effectiveness. Nevertheless, you gain significant safety, functional mobility, and maintenance.
Individual methods provided by these tools are among the most basic for anyone faced with “DeprecationWarning: executable_path has been deprecated, please pass in a Service object“.
If you still need help or have basic Python and Anaconda questions, a growing group of people is usually willing to help. Furthermore, we predict a more inventive day full of new ideas and scripts.
Leave a comment