Mac で Selenium + Chrome を使っていて、Chromeバージョンが 115 以上になって chromedriver がインストールできない場合

投稿者: ytyng 8ヶ月, 1週間 前

Mac で Selenium を使っていて、下記のようなエラーが出て Selenium 経由で Chrome が使えない場合の対応

This version of ChromeDriver only supports Chrome version 114
Current browser version is 116.0.5845.96 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

または、最新の chromedriver をインストールしても下記エラーが出てしまう場合の対応。

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

chromedriver のダウンロードページを見る

https://chromedriver.chromium.org/downloads

すると、 If you are using Chrome version 115 or newer, please consult the Chrome for Testing availability dashboard. This page provides convenient JSON endpoints for specific ChromeDriver version downloading.

と書いてある。

なので、json endpoint を見る。

https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json

リリース情報が json になっているので、本来はスクリプトで自動処理を作るのが良いが、今回は急ぎだったので手作業で対応する。

curl 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json' | jq | less

で、json の内容を見て、 116 を検索し、さらにその周辺の mac-arm64 を探すと、

          {
            "platform": "mac-arm64",
            "url": "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5791.0/mac-arm64/chrome-mac-arm64.zip"
          },
          {
            "platform": "mac-arm64",
            "url": "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5791.0/mac-arm64/chromedriver-mac-
arm64.zip"
          },

この2つの行が見つかる。

それぞれの URL から、chromedriver と 自動操作用の Chrome ( Google Chrome for Testing )をダウンロードする。

chromedriver はパスの通ったディレクトリに入れる。

既に過去に chromedriver を使ったことがある場合、 which chromedriver で場所を特定する。 私は homebrew で入れてたので /opt/homebrew/bin/chromedriver にあったので、上書きした。

Google Chrome for Testing は、Mac のアプリケーションディレクトリに入れる

それで Selenium の chromedriver が使えるようになる。

追記:

自動更新するスクリプトを作りました。

https://www.ytyng.com/blog/download-chromedriver-and-deploy-to-path/

現在未評価

コメント

アーカイブ

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011