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


el = driver.find_element_by_xpath(“ / html / body / div 2 / input”)
webdriver.ActionChains(driver).move_to_element(el).click(el).perform()


保持红色按钮的iframe:

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


重要说明:想象jsfiddle.net是主机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中完成操作后,您可以使用以下方法切换回顶部框架:

driver.switch_to_default_content()

10-07 12:04
查看更多