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?

1

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.