Click on a field with multiple Selenium results

Asked

Viewed 168 times

0

In my test script, I’m doing a system search that brings me 4 results.

Resultado busca

I need to make a method that selects only a specific result (in my case the 4th).
I tried it this way, but it didn’t work.

//CÓDIGO DO MEU PAGE OBJECT "DSL"
public void selectResultBusca(By locator, String selecao){
        WebElement resultBusca = navegador.findElement(locator);
        Select combo = new Select(resultBusca);
        combo.selectByVisibleText(selecao);
    }

//CÓDIGO DE TESTE
dsl.selectResultBusca(By.xpath("//*[@id=\"ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_"
                + "mfsPlanoPrevidenciario_ctl00_ctl10_ctl00\"]/tbody"), planoPrev);

Follow the HTML of the page referring to the image search box.
I did not put all HTML due to having many characters.

<div class="CM_lightbox" style="overflow: hidden;">
                <div class="CM_lightboxTitle">
                    <span>Procurar Registros</span><a class="CMLinkButton" href="javascript:__doPostBack('ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl06','')"><span class="closeLightbox"><br></span></a>
                </div><div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_tsMain" class="RadTabStrip RadTabStrip_Default RadTabStripTop_Default RadTabStripTop">
                    <div class="rtsLevel rtsLevel1">
                        <ul class="rtsUL"><li class="rtsLI rtsFirst"><a class="rtsLink rtsBefore" href="#"><span class="rtsOut"><span class="rtsIn"><span class="rtsTxt">Busca</span></span></span></a></li><li class="rtsLI rtsLast"><a class="rtsLink rtsSelected" href="#"><span class="rtsOut"><span class="rtsIn"><span class="rtsTxt">Resultado</span></span></span></a></li></ul>
                    </div><input id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_tsMain_ClientState" name="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_tsMain_ClientState" type="hidden" autocomplete="off" value="{&quot;selectedIndexes&quot;:[&quot;1&quot;],&quot;logEntries&quot;:[],&quot;scrollState&quot;:{}}">
                </div><div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_mpMain" class="RadMultiPage RadMultiPage_Default CMAutoSearchWrapper" style="max-height: 224.774px;">
                    <div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_pvParams" class="rmpView rmpHidden CMAutoSearchComponentPnl">
                        <div class="CMAutoSearchComponentGroupPnl">
                            <span><div class="CMAutoSearchLinha">
                                <div class="CMAutoSearchLabel">
                                    <span>Plano Previdenciário</span>
                                </div><div class="CMAutoSearchMethod grid_3">
                                    <div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl04" class="RadComboBox RadComboBox_Default" style="width:160px;white-space:normal;">
                                        <table summary="combobox" border="0" style="border-width:0;border-collapse:collapse;width:100%">
                                            <tbody><tr class="rcbReadOnly">
                                                <td class="rcbInputCell rcbInputCellLeft" style="width:100%;"><input name="ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl08$ctl04" type="text" class="rcbInput radPreventDecorate" id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl04_Input" value="Começa com" readonly="readonly" autocomplete="off"></td><td class="rcbArrowCell rcbArrowCellRight"><a id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl04_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td>
                                            </tr>
                                        </tbody></table><div class="rcbSlide" style="z-index:6000;display:none;"><div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl04_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Default "><div class="rcbScroll rcbWidth"><ul class="rcbList"><li class="rcbItem">Começa com</li><li class="rcbItem">Contém texto</li><li class="rcbItem">Diferente</li><li class="rcbItem">Igual</li><li class="rcbItem">Não nulo</li><li class="rcbItem">Nulo ou vazio</li><li class="rcbItem">Nenhum</li><li class="rcbItem">Termina Com</li></ul></div></div></div><input id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl04_ClientState" name="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl04_ClientState" type="hidden" autocomplete="off">
                                    </div>
                                </div><div class="CMAutoSearchValue grid_4">
                                    <span id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl06_wrapper" class="RadInput RadInput_Default" style="white-space:normal;"><input id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl06" name="ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl08$ctl06" size="20" class="riTextBox riEnabled" value="TCS" type="text"><input id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl06_ClientState" name="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl08_ctl06_ClientState" type="hidden" autocomplete="off" value="{&quot;enabled&quot;:true,&quot;emptyMessage&quot;:&quot;&quot;,&quot;validationText&quot;:&quot;TCS&quot;,&quot;valueAsString&quot;:&quot;TCS&quot;,&quot;lastSetTextBoxValue&quot;:&quot;TCS&quot;}"></span>
                                </div><div>
                                    <input type="button" name="ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl08$ctl08" value="" onclick="javascript:__doPostBack('ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl08$ctl08','')" class="CMAutoSearchCaseButtonOn" caseselection="On">
                                </div>
                            </div></span>
                        </div>
                    </div><div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_pvResult" class="rmpView">
                        <div class="CMAutoSearchComponentGroupPnl">
                            <div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10" class="RadGrid RadGrid_Default" tabindex="0">

                            <table class="rgMasterTable" border="0" id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ctl00" style="width:100%;table-layout:auto;empty-cells:show;">
                                <colgroup>
        <col>
    </colgroup>
<thead>
                                    <tr>
                                        <th scope="col" class="rgHeader"><a onclick="Telerik.Web.UI.Grid.Sort($find('ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ctl00'), 'Descricao'); return false;" title="Click here to sort" href="javascript:__doPostBack('ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl10$ctl00$ctl02$ctl01$ctl00','')">Plano Previdenciário</a></th>
                                    </tr>
                                </thead><tbody>
                                <tr class="rgRow" id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ctl00__0">
                                    <td>TCSPREV/BRTPREV/Fund-Incorp</td>
                                </tr><tr class="rgAltRow" id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ctl00__1">
                                    <td>TCSPREV/BRTPREV/Alt-Incorp</td>
                                </tr><tr class="rgRow" id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ctl00__2">
                                    <td>TCSPREV/BRTPREV Incorp</td>
                                </tr><tr class="rgAltRow" id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ctl00__3">
                                    <td>TCSPREV</td>
                                </tr>
                                </tbody>

                            </table><div id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_SharedCalendarContainer" style="display:none;">

                            </div><input id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ClientState" name="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_ctl10_ClientState" type="hidden" autocomplete="off">    </div>

                        </div><div class="CMAutoSearchButtonPnl">
                            <a class="CMLinkButton" href="javascript:__doPostBack('ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl12','')"><span class="btnAdicionar">Confirmar</span></a><a class="CMLinkButton" href="javascript:__doPostBack('ctl00$ctl00$placeHolderMain$mainWebCad$misPlanoPrevidenciario$mfsPlanoPrevidenciario$ctl00$ctl13','')"><span class="btnAdicionar">Selecionar todos</span></a>
                        </div>
                    </div><input id="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_mpMain_ClientState" name="ctl00_ctl00_placeHolderMain_mainWebCad_misPlanoPrevidenciario_mfsPlanoPrevidenciario_ctl00_mpMain_ClientState" type="hidden" autocomplete="off">
                </div><div class="buttonContainer">

                </div>
            </div>
  • Friend, first, put the page HTML in the question, so we can investigate what is happening.

  • I added the HTML of the search box. The HTML of the page has many characters.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.