Select iframe using Python + Selenium

后端 未结 6 702
Happy的楠姐
Happy的楠姐 2020-11-22 12:13

So, I was absolutely baffled as to how to do this in Selenium, and couldn\'t find the answer anywhere, so I\'m sharing my experience.

I was trying to select an ifram

6条回答
  •  温柔的废话
    2020-11-22 12:43

    You don't need to use JavascriptExecutor. All you needed to do was switch into the frame and then switch back out, like so:

    // do stuff on main window
    driver.switch_to.frame(frame_reference)
    // then do stuff in the frame
    driver.switch_to.default_content()
    // then do stuff on main window again
    

    As long as you are careful with this, you will never have a problem. The only time I always use a JavascriptExecutor is to get window focus since I think using Javascript is more reliable in that case.

提交回复
热议问题