LoginSignup
1
0

Selenium実行時に出たunknown error

Last updated at Posted at 2023-06-05

環境

Python 3.11.3
Selenium 4.9.1
Google Chrome/ChromeDriver 113.0.5672.63

WebDriverException: Message: unknown error

手元のローカルPCでは問題なく動作するがDocker上で動かしたところ以下のエラーが出力された

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.

このエラーに続いて以下のメッセージが表示されており、どうやらChromeの起動そのものが失敗していた

(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

試しにChrome起動時のオプションでChromeDriverを直接指定したりしたが状況は改善されず。。

options.add_argument("webdriver.chrome.driver=/path/to/chromedriver")
driver = webdriver.Chrome(options=options)

他にも色々と試したが、以下のオプションを指定することで無事解決

options.add_argument("--headless")
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=options)
  • --headless
    • ヘッドレスモードで起動
  • --no-sandbox
    • サンドボックスを使わずに起動

なお、Dockerイメージはselenium/standalone-chromeを使用していますが、Dockerfileにビルド処理を追加してあげることで上記オプションを指定することなく起動できるとは思いますが試せてません。

もしくはXvfbをインストールする。

1
0
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
1
0