LoginSignup
7
5

More than 5 years have passed since last update.

headlessをつけると要素が取れないとき

Last updated at Posted at 2019-02-01

私がしたかったこと

  • driver.find_element_by_link_text('メニュー').click()といった感じで、 リンクテキストを用いて要素をクリックしたい
  • headlessをつけたい

ところがどっこいエラーが発生

エラー内容は、
リンクテキストをクリックするところでの、NoSuchElementException

でもheadlessをつけないとエラーは出ず。

解決法

言語設定してあげることで1発で解決。

options = ChromeOptions()
options.add_argument('--headless')
options.add_argument('--lang=ja-JP')

driver = Chrome(options=options)

options.add_argument('--lang=ja-JP')の言語設定をしてあげることで、
headlessをつけても無事動くようになりました。

7
5
1

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
7
5