1

When I run my Selenium 4.1 script in Python 3.10, I get a warning message that the keyword argument executable_path is deprecated. See script below.

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

edge_path = 'edgedriver_win64/msedgedriver.exe'
driver = webdriver.Edge(executable_path=edge_path)
driver.get('https://bing.com')

element = driver.find_element(By.ID, 'sb_form_q')
element.send_keys('WebDriver')
element.submit()

time.sleep(10)
driver.close()
driver.quit()

Warning message:

script.py:13: DeprecationWarning: executable_path has been deprecated,
please pass in a Service object
  driver = webdriver.Edge(executable_path=edge_path)

How do I fix this?

VirtualScooter
  • 1,792
  • 3
  • 18
  • 28
  • Does this answer your question? [DeprecationWarning: executable\_path has been deprecated selenium python](https://stackoverflow.com/questions/64717302/deprecationwarning-executable-path-has-been-deprecated-selenium-python) – Prophet Jan 27 '22 at 22:24

1 Answers1

1

To fix this, import the Service class for the Edge webdriver (line 4 below), then create a service object with the executable path (line 7 below). Subsequently, pass the service object as a keyword argument to webdriver creation call (line 8 below).

The sample script becomes:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.edge.service import Service

edge_path = 'edgedriver_win64/msedgedriver.exe'
service = Service(executable_path=edge_path)
driver = webdriver.Edge(service = service)
driver.get('https://bing.com')

element = driver.find_element(By.ID, 'sb_form_q')
element.send_keys('WebDriver')
element.submit()

time.sleep(10)
driver.close()
driver.quit()
VirtualScooter
  • 1,792
  • 3
  • 18
  • 28