如何点击红色按钮here从主机A(在本例中为jsfiddle.net)使用selenium python? (javascript限制政策错误不允许我这样做)。另外我不想直接点击红色按钮。 谢谢。
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。
最佳答案
您需要使用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()
关于python-3.x - 使用 Python selenium 单击 iframe 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23688279/