Home > Net >  Searching for records with capybara
Searching for records with capybara

Time:06-13

Our Thomas Walpole helped me a lot in this logic below. I have a problem, when the record is on the first page the button that moves to the next page in the list is disabled. How do I so if the record is on the first page it does not enter the loop that scans the screen looking for this record?

def cad_diametro_material_ativo
    input_codigo.send_keys('aut_Server_AL')
    input_ordem.send_keys('1')
    @gera_material_ativo =  'AUT_Server_ALUMINIO_ATIVO'  rand(1..99).to_s
    input_descricao.send_keys(@gera_material_ativo)
    btn_inserir.click
    until page.has_css?("td", text: @gera_material_ativo, wait: 3) do
    btn_move_registros.click
    end
    find("td", text: @gera_material_ativo).click
    btn_cancelar.click
    end

    hml code

    <div id="AFRAME_14bb" onm ousedown="event.preventMoving=true;" style="display: inline-block; box-sizing: border-box; min-width: 100%;" >
       <a name="tvTDiametroMat"></a>
       <div >
          <div style="display:inline-block;width:100%"><img src="r/std/static/pixel.gif"  draggable="false" onclick="sendEvent(0,event,this,true,0,'','14bb','ControlMenu#','','','','','');">&nbsp;Diâmetro do Material</div>
       </div>
       <div id="TV-tvTDiametroMat">
          <div style="" >
             <div style="display:table;width:100%; background:inherit;">
                <div style="display:table-cell;vertical-align:top; background:inherit;" >
                   <div >
                      <div>1</div>
                      <div><img src="r/std/static/pixel.gif"  draggable="false"></div>
                      <div><img src="r/std/static/pixel.gif"  draggable="false"></div>
                      <div><img src="r/std/static/pixel.gif"  draggable="false" onclick="loadPage('tvTDiametroMat','1','11',2);"></div>
                      <div><img src="r/std/static/pixel.gif"  draggable="false" onclick="loadPage('tvTDiametroMat','10','11',2);"></div>
                   </div>

enter image description here

CodePudding user response:

until page.has_css?("td", text: @gera_material_ativo, wait: 3) do
  btn_move_registros.click
end

will only click the button to go to the next page if the first page doesn't have the desired td element within the specified wait period. If it is clicking to go the next page even though you believe the expected td is on the first page then it's likely your wait setting isn't long enough for the first page to render. Try increasing the wait value

  • Related