在切換到新的版本的 selenium 時,顯示的錯誤訊息。
before:
from selenium import webdriver
chrome_driver_path = 'C:/Users/Morteza/Documents/Dev/chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver_path)
url = "https://www.google.com"
driver.get(url)
after:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s=Service('C:/Users/Morteza/Documents/Dev/chromedriver.exe')
browser = webdriver.Chrome(service=s)
url='https://www.google.com'
browser.get(url)
This error message…
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
…implies that the key executable_path
will be deprecated in the upcoming releases.
This change is inline with the Selenium 4.0 Beta 1 changelog which mentions:
Deprecate all but
Options
andService
arguments in driver instantiation. (#9125,#9128)
Solution
Once the key executable_path
is deprecated you have to use an instance of the Service()
class as follows:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service('C:/Users/.../chromedriver.exe')
driver = webdriver.Chrome(service=s)
TL; DR
You can find a couple of relevant detailed discussion in: