コンテンツ
事象
Seleniumを使ったアプリを実行しようとすると、以下のエラーが発生。
session not created: This version of ChromeDriver only supports Chrome version xx
Traceback (most recent call last):
File "someapp.py", line 55, in <module>
main()
File "someapp.py", line 11, in main
browser = webdriver.Chrome('/usr/local/bin/chromedriver')
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 83
前提条件(発生環境)
- MacOS Big Sur
- Python
- Google Chrome
- chromedriver
原因
Google Chromeとchromedriverのバージョンがずれたことに起因します。
本環境では、Chromeがアップデートされたことでバージョンがずれました。
対処
chromedriverをアップデートします。
$ brew update
~~~
==> Updated Casks
chromedriver ✔
~~~
$ brew upgrade chromedriver
==> Upgrading 1 outdated package:
chromedriver 87.0.4280.20 -> 89.0.4389.23
==> Upgrading chromedriver
==> Downloading https://chromedriver.storage.googleapis.com/89.0.4389.23/chromedriver_mac64.zip
######################################################################## 100.0%
==> Unlinking Binary '/usr/local/bin/chromedriver'
==> Linking Binary 'chromedriver' to '/usr/local/bin/chromedriver'
==> Purging files for version 87.0.4280.20 of Cask chromedriver
🍺 chromedriver was successfully upgraded!
chromedriverをアップデートした後、以下のエラーが発生する可能性があります。
Traceback (most recent call last):
File "someapp.py", line 55, in <module>
main()
File "someapp.py", line 11, in main
browser = webdriver.Chrome('/usr/local/bin/chromedriver')
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/Users/akihiro/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/chromedriver unexpectedly exited. Status code was: -9
Macの環境設定
> セキュリティ
からchromedriverを許可することで解消します。