1
2

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 3 years have passed since last update.

Selenium Python iFrameがある時の処理方法

Posted at

Seleniumを実行しているときiframeの扱いに迷った

iframe内の要素をクリックしたかったのだが、なぜか要素を取得できなかった。
そんな時の備忘録。

iframe内の要素をクリックしたい場合は、フレームを切り替える必要がある。

from selenium import webdriver

#ドライバー作成
driver = webdriver.Chrome(executable_path='chromedriver.exe')

#ここでフレーム要素を取得
frameElement = driver.find_element_by_id("dialog")

#ここでフレームを切り替える
driver.switch_to_frame(frameElement) 

##何らかの処理

#親フレームに戻す
driver.switch_to.default_content()
1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?