LoginSignup
14
12

More than 1 year has passed since last update.

Selenium Webdriverの指定方法(executable_path)が非推奨になったことへの対処法

Posted at

これまでの記述方法

これまでwebdriverはexecutable_pathを指定して

from selenium import webdriver

driver = webdriver.Chrome(executable_path='path/to/chrome')

またはWebdriver Managerを使って

from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())

のように書いていました。

しかし、この記述方法が非推奨になったことで、

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

という警告が出るようになりました。

新しい記述方法

警告にある通り、Serviceオブジェクトを使って

from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service('path/to/chrome'))

またはWebdriver Managerを使って

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

と記述すれば警告が出なくなります。

その他

こちらのStack Overflowの質問を参考にしました。
Qiita初投稿なので読みにくい・一部間違いがあるかもしれませんがご容赦・ご指摘お願いします。

14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12