In this python program, we will understand how to resolve the Executable path has been deprecated in selenium Python by bypassing the executable path Manually and by using ChromeDriverManager to Passing Executable Path. The warning we get is “DeprecationWarning: executable_path has been deprecated “.We will cover how to resolve it with different web drivers.
1. Manually Passing Executable Path for Brower’s 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 “DeprecationWarning: executable_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()
- How to Install selenium on windows Python
- How to install selenium in VSCode
- How to open chrome browser in selenium Python
- How to open Edge browser in selenium Python
- How to open Firefox browser in selenium Python
- Executable path has been deprecated in selenium Python
- Solved version of ChromeDriver only supports Chrome version 98
- How to make test suite in selenium Python
1.1 Firefox Executable path has been deprecated in selenium Python
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 Edge Executable path has been deprecated in selenium Python
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()