click on iframe element using Python selenium

时光怂恿深爱的人放手 提交于 2019-12-19 10:04:53

问题


how can i click the red button here from Host A (in this example jsfiddle.net) using selenium python? (java script limitation policy error do not let me to do it). also i do not want to click directly Red Button. thanks.

el =driver.find_element_by_xpath("/html/body/div2/input")
webdriver.ActionChains(driver).move_to_element(el).click(el).perform()

iframe that keeps red button:

<iframe src="http://www.myhostb.blogfa.com/" width="500" height="300">
</iframe>

important note: imaging that jsfiddle.net is Host A.

DEMO


回答1:


You need to use switch_to_frame()

driver.switch_to_frame("result")
driver.switch_to_frame(driver.find_element_by_css_selector("body>iframe"))
driver.find_element_by_css_selector("input.ex2").click()

Once you're done in the iframe, you can switch back to the top frame using:

driver.switch_to_default_content()


来源:https://stackoverflow.com/questions/23688279/click-on-iframe-element-using-python-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!