0

I have this webpage with the following HTML code:

i have tried this. WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.iframeTGR"))) WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"busqueda"))) WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//input[@value='Aceptar'][@class='boton']"))).click()

but Message: stale element reference: element is not attached to the page document

enter image description here And I need to access to the from's field and click the input at the bottom of the form.

<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>
2
  • 1
    Can you post the html from the picture in text form. Commented Oct 9, 2020 at 20:59
  • @Jortega question updated Commented Oct 9, 2020 at 21:18

1 Answer 1

0

To Access nested iframe you need to switch to both iframes in order to access input element.

Use WebDriverWait() and wait for frame_to_be_available_and_switch_to_it()

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,".embed-responsive-item.iframeTGR")))
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"id_busqueda")))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input[value='Aceptar']"))).click()

You need to import following library

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, but i have the following error message: WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"id_busqueda"))) File "C:\Python38\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: @Kundruk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.