29
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonでSeleniumを扱ってhtmlに埋め込まれたJavaScriptを実行

Last updated at Posted at 2017-12-07

  • 最近良くSeleniumを使います.
  • htmlに埋め込まれたJavaScriptを実行する方法を備忘録的に残しておきます.

とりあえずこんな感じで書けます

browser.execute_script('javascript:hogehoge();')

引数はstr型ですね.
hogehoge()は実行したいJavaScriptです.

例えばリンクをクリックしてリンク先のファイルをダウンロードしたいという時に,

driver.find_element_by xxx .click()

で要素を取得してボタンをクリックするのではなく,埋め込まれたJavaScriptを実行した方が上手くいったりします.

29
24
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
29
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?