使用Python硒单击iframe元素 [英] click on iframe element using Python selenium

查看:118
本文介绍了使用Python硒单击iframe元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从主机A(在此示例jsfiddle.net)中点击红色按钮此处使用硒蟒蛇? (Java脚本限制策略错误不允许我这样做).我也不想直接单击红色按钮. 谢谢.

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/div 2 /input")
webdriver.ActionChains(driver).move_to_element(el).click(el).perform()

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

保持红色按钮的iframe:

iframe that keeps red button:

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

重要说明:想象jsfiddle.net是主机A.

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

演示

DEMO

推荐答案

您需要使用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()

iframe中完成操作后,您可以使用以下方法切换回顶部框架:

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

driver.switch_to_default_content()

这篇关于使用Python硒单击iframe元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆