Executable path has been deprecated in selenium Python

In this python program, we will understand how to resolve the Executable path has been deprecated in selenium Python bypass executable path Manually and by using ChromeDriverManager to Passing Executable Path. The warning we get is “DeprecationWarningexecutable_path has been deprecated “.We will cover how to resolve it with different web drivers.

1. Manually Passing Executable Path for Browers driver


In this example, we have passed the executable path of the web browser driver “C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\Scripts\chromedriver.exe” to the service object, and resolve “DeprecationWarningexecutable_path has been deprecated “.”

Passing the service object to WebDrive.chrome() Will automatically open the chrome browser.

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


service  = Service("C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts\\chromedriver.exe")
driver = webdriver.Chrome(service = service)
driver.maximize_window()
driver.get("https://google.com")
title = driver.title
print(title) 
assert "Google" in title
driver.quit()


1.1 For Firefox web browser


We can use the below code to resolve the problem. Change the execution path to where you have downloaded and unzip the “geckodriver.exe”

from selenium import webdriver
from selenium.webdriver.firefox.service import Service


service  = Service("C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts\\geckodriver.exe")
driver = webdriver.Firefox(service = service)
driver.maximize_window()
driver.get("https://google.com")
title = driver.title
print(title) 

driver.quit()

1.2 For Edge Web brower


We can below code to resolve the problem in the Edge browser.

from selenium import webdriver
from selenium.webdriver.edge.service import Service


service  = Service("C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts\\msedgedriver.exe")
driver = webdriver.Edge(service = service)

driver.maximize_window()
driver.get("https://google.com")
title = driver.title
print(title) 

driver.quit()



2. Using ChromeDriverManager to Passing Executable Path


In this example instead of passing the executable path Manually. We have passed the service argument value using ChromeDriverManager(). The chrome driver manager automatically handles the executable path.

We are opening the chrome browser by using python selenium.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")
driver.quit()