Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python html中的Selenium和iframe_Python_Iframe_Selenium_Selenium Webdriver - Fatal编程技术网

Python html中的Selenium和iframe

Python html中的Selenium和iframe,python,iframe,selenium,selenium-webdriver,Python,Iframe,Selenium,Selenium Webdriver,无法对iframe使用send_key()。如何选择此iframe以及其中的哪个元素应用于send_key() 和iframe html代码 <iframe class="textarea" src="/framework/html/blank.html" style="width: 99%; border-width: 1px; height: 332px;"> #document <html webdriver="true"> <head> </h

无法对iframe使用send_key()。如何选择此iframe以及其中的哪个元素应用于send_key()

和iframe html代码

<iframe class="textarea" src="/framework/html/blank.html" style="width: 99%; border-width: 1px; height: 332px;">
#document
<html webdriver="true">
<head>
</head>
<body> … </body>
</html>
</iframe>

#文件
… 
如何将值发送到描述?


还有一件事我想知道,当我在浏览器中选择“查看页面源代码”时,这个框架代码不会出现?

驱动程序。切换到.frame(driver.find\u element\u by_tag\u name(“iframe”),假设驱动程序是webdriver的健康实例。要继续使用默认内容,请执行
驱动程序。切换到.default\u content()

编辑:当您切换到所需的框架时,像往常一样定位您的webelement。我猜(但不确定)在您的情况下,这将是一个html/正文,所以

el=driver。通过xpath('html/body')查找元素。

应该没问题。表演

el.send\u keys('keys\u to\u send')

EDIT2:在发送键之前,您可能必须关注元素(单击应该可以完成这项工作,应该会出现子元素)。或者您可以通过JS放置所需的文本


driver.execute_script('document.body.innerHTML=“%s”'%text\u var)

要处理网页上的iFrame,您需要首先使用以下命令切换到网页上存在的iFrame: 驱动程序.切换到.帧(帧id)


本教程提供了一个工作示例,可以帮助您解决此问题。

对于给定的问题,公认的答案非常有效。不过,我有两个理由再添加一个答案,希望这个答案可以帮助其他人提出不同的问题

原因1:

接受的答案有一种处理网页内iFrame的方法。但是,有不同的方法来处理iFrame

  • 使用框架的索引位置
  • 使用框架的名称
  • 通过使用帧的id
原因2:

它使用driver.find\u element\u by_tag\u name(“iframe”)语句查找可能无法工作的iframe元素,或者在同一页面中有多个iframe元素时返回预期的iframe web元素

有很多文章详细解释了如何处理iframe


  • 对不起,我是新手。但是driver.switch_to_frame(driver.find_element_by_tag_name(“iframe”))如何使用这个东西将密钥发送到描述窗口?就像现在司机换成了frame@RATHI在requestedelement获得select时编辑了一个答案,send_keys()也在执行,没有错误,但页面上没有值。嘿,这里,使用这个答案作为参考。您使用driver.switch_to_frame,但其站点上的文档使用driver.switch_to.frame。哪一个是正确的?