Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 使用Selenium访问嵌套iFrame_Python_Selenium_Screen Scraping_Frames - Fatal编程技术网

Python 使用Selenium访问嵌套iFrame

Python 使用Selenium访问嵌套iFrame,python,selenium,screen-scraping,frames,Python,Selenium,Screen Scraping,Frames,我有以下HTML代码的网页: 我试过这个。 WebDriverWait(驱动程序,10)。直到(EC.frame\u to\u be\u available\u和\u switch\u to \u it((通过.CSS\u选择器,“iframe.iframeTGR”)) WebDriverWait(驱动程序,10)。直到(EC.frame_to_be___可用_和_switch_to_it((通过名称,“busqueda”)) WebDriverWait(driver,10).until(EC.

我有以下HTML代码的网页:

我试过这个。 WebDriverWait(驱动程序,10)。直到(EC.frame\u to\u be\u available\u和\u switch\u to \u it((通过.CSS\u选择器,“iframe.iframeTGR”)) WebDriverWait(驱动程序,10)。直到(EC.frame_to_be___可用_和_switch_to_it((通过名称,“busqueda”)) WebDriverWait(driver,10).until(EC.element可点击((By.XPATH,//input[@value='Aceptar'][@class='boton'])。点击()

但是消息:stale元素引用:元素未附加到页面文档

我需要访问from的字段并单击表单底部的输入

<section class="text-center" style="padding: 0"> <!-- class="d-block d-sm-none" style="padding: 0 10px;" -->
<div style="z-index: 0;">
    <iframe class="embed-responsive-item iframeTGR" src="https://www.tesoreria.cl/portal/portlets/acceso_usuario/cognito/CognitoController.jpf?vr=MzAzM2NhNjM1OGMyMmFkMDRjNjUwMWYxZGM4YjUyOTRhZjhlLDIwMjAtMTAtMDlUMjA6MzQ6MTFaLDc5OTA3NzkwLHYydUIzUHM1YkpxV0RSanQ3NUV3ZEIzTStDUUhvbDN4LHIxMCxDbGF2ZVRyaWJ1dGFyaWE=" style="border-width: 0px !important; min-height: 600px !important; width: 100% !important;">
        <html>
            <head>
                <link href="/portal/resources/css/tesoreria.css" rel="stylesheet" type="text/css">
                <link href="/portal/resources/css/tgrWp.css" rel="stylesheet" type="text/css">
            </head>
            <body>
                <iframe src="redireccion.jsp?redireccion=r10" name="busqueda" id="id_busqueda" class="tgr_wp_id_busqueda" scrolling="auto" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0">
                    <html lang="es"><head><link rel="stylesheet" href="/certificaWeb/resources/css/custom-theme/jquery-ui-1.10.4.custom.css">  
                        <link rel="stylesheet" href="/certificaWeb/resources/css/custom-theme/default.css">  
                        <link rel="stylesheet" href="/certificaWeb/resources/css/cssTGRlocal.css">
                                <title>
                                    Comprobantes de Pago
                                </title>
                                <meta name="modificado" content="29-08-2012 14:52, by mce">
                            </head>
                            <body marginwidth="0" marginheight="0">
                            
                           
                        
                            
                        <table align="center"> 
                          <tbody><tr> 
                            <td align="center"> <table class="tblAnchoMM tblForm"> 
                                <caption>
                                 Consulta Comprobante de pago 
                                </caption> 
                                <tbody><tr> 
                                  <td> <!--inicio tabla principal--> 
                                    <form action="/certificaWeb/comprobantes/pagos/doConsulta.do" method="post"> <br>        
                                     <br> 
                                    <table align="center" class="tblForm tblAnchoSS"> 
                                      <tbody><tr> 
                                        <th colspan="2"> Por favor ingresar el Rut del Contribuyente</th> 
                                      </tr> 
                                      <tr> 
                                        <td class="tblFormTxt" width="60%">Tipo de Contribuyente </td> 
                                        <td> <input type="hidden" name="wlw-select_key:{actionForm.tipo}OldValue" value="true">
                                        <select name="wlw-select_key:{actionForm.tipo}" id="tipoCont" accesskey="s" onchange="chTipo(this.value)">
                                        <option value="2">ROL</option>
                                        <option value="1" selected="">RUT</option></select></td> 
                                      </tr> 
                                      <tr id="tipoRol" style="display: none;"> 
                                        <td class="tblFormTxt">Comuna / Rol / SubRol </td> 
                                        <td><input type="text" name="{actionForm.rolComuna}" id="comuna" class="formularios" maxlength="3">
                                                        <input type="text" name="{actionForm.rolRol}" id="rol" class="formularios" maxlength="5">
                                                        <input type="text" name="{actionForm.rolSubrol}" id="subrol" class="formularios" maxlength="3"> </td> 
                                      </tr> 
                                      <tr id="tipoRut" style="display: block;"> 
                                        <td class="tblFormTxt">Rut </td>
                                     <td> 
                                             <input type="text" name="{actionForm.rut}" id="rut" maxlength="8" size="8" disabled="" readonly="" onkeyup="{solonumeros(this,this.value.charAt(this.value.length-1))}"> - <input type="text" name="{actionForm.dv}" id="dv" class="formularios" maxlength="1" size="1" disabled="" readonly="" style="width: 15px;">
                                          </td>       
                                      </tr> 
                                      <tr> 
                                        <td class="tblFormTxt">Numero de Formulario 
                                                        </td> 
                                        <td> <input type="text" name="{actionForm.formNum}" id="formulario" maxlength="5" onkeyup="{solonumeros(this,this.value.charAt(this.value.length-1))}"></td> 
                                      </tr> 
                                      <tr> 
                                        <td class="tblFormTxt">Folio de Formulario </td>
                                        <td> <input type="text" name="{actionForm.formFolio}" id="folio" maxlength="10" onkeyup="{solonumeros(this,this.value.charAt(this.value.length-1))}"></td> 
                                      </tr> 
                                      <tr> 
                                        <td class="tblFormTxt">Fecha desde <label style="color:#456789; font-size:70%;">(DD-MM-AAAA)</label></td>
                                       <td> <input type="text" name="{actionForm.formDesde}" id="formDesde" value="01-10-2020" maxlength="10" style="width: 80px; height: 20px;">
                                         <!--   <td> <input type="text" id="desde" name="L15" size="10"  class="classFecha2" align="middle" style="background:#cccccc" readonly>-->
                                        </td> 
                                       <!-- <td  class="tblFormTxt" width="37%" style="color:#456789; font-size:70%;">(aaaa-mm-dd)</td>-->
                                      </tr> 
                                      <tr> 
                                        <td class="tblFormTxt">Fecha hasta <label style="color:#456789; font-size:70%;">(DD-MM-AAAA)</label></td>  
                                          <td> <input type="text" name="{actionForm.formHasta}" id="formHasta" value="09-10-2020" maxlength="10" style="width: 80px; height: 20px;">
                                          <!--   <td> <input type="text" id="hasta" name="L15" size="10" class="classFecha2" align="middle" style="background:#cccccc" readonly> -->
                                        </td>
                                        <!-- <td  class="tblFormTxt" width="37%" style="color:#456789; font-size:70%;">(aaaa-mm-dd)</td>-->
                                      </tr> 
                                    </tbody></table> 
                                    <br> 
                                    <input type="hidden" name="rutContribuyente" id="rutContribuyente" value="79907790">
                                    <input type="hidden" name="dvContribuyente" id="dvContribuyente" value="6">
                        
                        
                        <!--<input type="hidden" name="almacenista"  id="almacenista" value="<!%=almacenista%>"> -->
                                    
                                    <div align="center"> <input type="submit" class="boton" value="Aceptar">   </div> 
                                    </form>
                                     </td> 
                                  <!--fin tabla principal--> 
                                </tr> 
                            </tbody></table></td> 
                          </tr> 
                        </tbody>
                    </table>    
                       
                    </body>
                    </html>
                </iframe>
            </body>
        </html>
    </iframe> <!-- https://www.tesoreria.cl/LoginPortalCognito/login?go=rpl6_w81 -->
</div>

帕戈综合酒店
帕戈综合领事馆


赞成安格尔·拉特·德尔布恩特 分担责任 罗尔 车辙 Comuna/Rol/SubRol 车辙 - 公式数 公式对开本 Fecha desde(DD-MM-AAAA) Fecha hasta(DD-MM-AAAA)

要访问嵌套的
iframe
您需要切换到这两个
iframe
才能访问输入元素

使用
WebDriverWait
()并等待
frame\u可用,然后切换到\u it
()

您需要导入以下库

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

您能以文本形式发布图片中的html吗。@Jortega问题更新感谢您的回答,但我有以下错误消息:WebDriverWait(驱动程序,10)。直到(EC.frame\u to\u be\u available\u和\u switch\u to\u it((By.ID,“ID\u busqueda”))文件“C:\Python38\lib\site packages\selenium\webdriver\support\wait.py”,第80行,在Till raise TimeoutException(消息、屏幕、堆栈跟踪)中,selenium.common.exceptions.TimeoutException:message:@Kundruk
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC