当前位置: 首页 > 知识库问答 >
问题:

如何构建一个方法来遍历WebElements并返回使用Selenium显示的WebElements

澹台奇略
2023-03-14

因此,页面中充满了许多类似的属性,如下面的两个元素。例子:

<button id="exibe_codigo_de_barras_210888-1" data-context="minhas-contas_conta_codigo-barras_btn-ver-codigo-barras-colapse" font-size="0.875rem" width="100%" class="styled__Button-sc-6mz6kj-0 gMrMBo" style="" xpath="1">VER CÓDIGO DE BARRAS <span class="sc-1o2smz3-2 dAGdGd styled__Arrow-tuh5ii-0 iYDeiw"><svg width="12px" height="8px" viewBox="0 0 12 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><polygon id="chevron" points="7.41 8 12 12.9446694 16.59 8 18 9.52226721 12 16 6 9.52226721"></polygon></defs><g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Interface/Seta-expandir" transform="translate(-6.000000, -8.000000)"><mask id="mask-2" fill="white"><use xlink:href="#chevron"></use></mask><use id="Seta-expandir" fill="#D82482" fill-rule="nonzero" xlink:href="#chevron"></use></g></g></svg></span></button>
<button id="exibe_codigo_de_barras_210888-2" data-context="minhas-contas_conta_codigo-barras_btn-ver-codigo-barras-colapse" font-size="0.875rem" width="100%" class="styled__Button-sc-6mz6kj-0 gMrMBo" style="" xpath="1">VER CÓDIGO DE BARRAS <span class="sc-1o2smz3-2 dAGdGd styled__Arrow-tuh5ii-0 iYDeiw"><svg width="12px" height="8px" viewBox="0 0 12 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><polygon id="chevron" points="7.41 8 12 12.9446694 16.59 8 18 9.52226721 12 16 6 9.52226721"></polygon></defs><g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Interface/Seta-expandir" transform="translate(-6.000000, -8.000000)"><mask id="mask-2" fill="white"><use xlink:href="#chevron"></use></mask><use id="Seta-expandir" fill="#D82482" fill-rule="nonzero" xlink:href="#chevron"></use></g></g></svg></span></button>

我使用PageObject和PageFactory获取元素,并将它们放入如下数组:

@FindAll(@FindBy(how = How.CSS, using = "[data-context=minhas-contas_conta_codigo-barras_btn-ver-codigo-barras-colapse]"))
public List<WebElement> btnVerCodigoDeBarras;

问题是:我需要单击其中一个类似的按钮,而不使用索引(因为结果是很难维护)。我想到了一种方法,我可以收集列表中的所有WebElement并返回屏幕上显示的单个WebElement(我乐于接受新想法),因此以下是我尝试过但未成功的两种方法:

public static WebElement WaitForElementVisibleInArray(List<WebElement> elements) {
    boolean arrayNotEmpty = elements.size() > 0;
    if (arrayNotEmpty) {
        for (Iterator<WebElement> i = elements.iterator(); i.hasNext(); ) {
            WebElement element = i.next();
            if (element.isEnabled() && element.isDisplayed()) {
                return element;
            }
        }
    }
    return null;
}
public static WebElement WaitForElementVisibleInArray(List<WebElement> elements) {
    boolean arrayNotEmpty = elements.size() > 0;        
    if (arrayNotEmpty) {            
        Iterator<WebElement> it = elements.iterator();
        WebElement element;
        while (it.hasNext()) {
            element = it.next();
            if (element.isEnabled() && element.isDisplayed()) {
                return element;
            }
        }
    }
    return null;
}

我找了很多东西,没能解决这个问题。提前谢谢你!

编辑:

根据要求,下面是包含几个div子级的div父级的两个示例:First div:

<div class="sc-1o2smz3-8 bdzhlP styled__Row-sc-13w6d15-0 SpKwt"><div><button id="envia_codigo_de_barras_210888-1" data-context="minhas-contas_conta_codigo-barras_btn-enviar" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z"></path></svg> Enviar</button><div class="modal styled__Modal-a94357-0 fQRtzL"><aside class="overlay styled__Overlay-gtv01n-0 joIHPo"></aside><div radius="4" display="flex" direction="column" width="100%" height="auto" cursor="initial" order="0" class="Modal__Container-sc-13j9751-1 cbeGrw Container__ContainerStyle-sc-1iqy2ia-0 dVRtOm" style="max-width: 500px; display: flex; flex: 1 1 0%;"><button class="fechar styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg width="30" height="30" viewBox="0 0 30 30"><path fill="#9B9B9B" fill-rule="evenodd" d="M13.106 15.09L8.227 19.85l1.625 2.035 5.119-4.976 5.099 4.976 1.882-1.83-5.109-4.966 5.109-4.967-1.882-1.83-5.1 4.976-5.118-4.976-1.625 2.035 4.879 4.762zM15 30C6.716 30 0 23.284 0 15 0 6.716 6.716 0 15 0c8.284 0 15 6.716 15 15 0 8.284-6.716 15-15 15z"></path></svg></button><div class="Row styled__Row-sc-13w6d15-0 gPFeBI" data-context="popup_enviar-codigo-barras" style="width: 100%;"><div class="col styled__Col-sc-4ph28m-0 bWdzYK"><div class="Row styled__Row-sc-13w6d15-0 gPFeBI"><h2 class="sc-1h9tg9u-1 ieQsBc Title__TitleStyle-sc-5b4olk-0 gZiyVB" font-weight="Regular" width="100%">Enviar código de barras</h2></div><div class="Row styled__Row-sc-13w6d15-0 cXZsiu"><div class="col styled__Col-sc-4ph28m-0 cEyrnf"><label class="progress-bar styled__Radio-sc-13c6bcq-0 jIgdvS" data-context="popup_enviar-codigo-barras_input-radio_forma-envio" id="envio_email"><input type="checkbox" checked=""><span></span><p font-size="18px" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" lineheight="1em" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 gTxJFk">&nbsp;E-mail</p></label></div><div class="Row styled__Row-sc-13w6d15-0 fKsxZO"></div><div class="col styled__Col-sc-4ph28m-0 cEyrnf"><label class="progress-bar styled__Radio-sc-13c6bcq-0 jIgdvS" data-context="popup_enviar-codigo-barras_input-radio_forma-envio" id="envio_sms"><input type="checkbox"><span></span><p font-size="18px" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" lineheight="1em" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 gTxJFk">&nbsp;SMS pra Celular Oi</p></label></div><div class="col styled__Col-sc-4ph28m-0 cEyrnf"></div></div><div class="Row styled__Row-sc-13w6d15-0 gPFeBI"><div class="col styled__Col-sc-4ph28m-0 cKjXbt"><fieldset class="styledFieldset-sc-1r2we57-0 jBoAvV"><input class="sc-1h9tg9u-0 dFDlQp styledInput__Input-sc-1apvofq-0 bkjwCX" id="informe_email" data-context="popup_enviar-codigo-barras_input-text_email" placeholder="Digite seu e-mail" maxlength="50" value=""><div class="sc-1h9tg9u-0 dFDlQp styledMessage-d8kpbw-0 gAaQEw"></div></fieldset></div></div><div class="Row styled__Row-sc-13w6d15-0 kRKEGz"><div class="col styled__Col-sc-4ph28m-0 cKjXbt"><button disabled="" id="submit_envio" data-context="popup_enviar-codigo-barras_input-submit" font-size="0.875rem" width="100%" class="styled__Button-sc-6mz6kj-0 crrbD">ENVIAR</button></div></div></div></div></div></div></div><button data-context="minhas-contas_conta_codigo-barras_btn-copiar" id="copia_codigo_de_barras_210888-1" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z"></path></svg> Copiar código</button><button data-context="minhas-contas_conta_codigo-barras_btn-baixar-pdf" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"></path></svg> Baixar PDF</button><button id="imprime_fatura_210888-1" data-context="minhas-contas_conta_codigo-barras_btn-imprimir" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg> Imprimir</button></div>

第二组:

<div class="sc-1o2smz3-0 dzkPUw styled__Row-sc-13w6d15-0 gPFeBI" data-context="minhas-contas_conta"><div class="col styled__Col-sc-4ph28m-0 cTsLBT" width="100%"><div class="Row styled__Row-sc-13w6d15-0 bTDNmX"><div class="col styled__Col-sc-4ph28m-0 cEyrnf"><div class="no-wrap styled__Row-sc-13w6d15-0 hfVmIP"><div class="col styled__Col-sc-4ph28m-0 hAdyfM"><label class="progress-bar styled__Radio-sc-13c6bcq-0 kXqgpo" id="seleciona_fatura_210888-2"><input type="checkbox"><span></span></label></div><div class="col styled__Col-sc-4ph28m-0 lnnClR"><div class="sc-1o2smz3-8 bdzhlP styled__Row-sc-13w6d15-0 fpsrZI"><h3 font-family="SimplonMedium" data-context="minhas-contas_conta_valor" font-weight="Regular" width="100%" class="Title__TitleStyle-sc-5b4olk-0 kCdfIG">R$ &nbsp;99,88&nbsp;</h3></div><p font-size="14px" lineheight="1.5em" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 bcIQEp">Vencimento: 11/03/2018</p><div class="Row styled__Row-sc-13w6d15-0 gPFeBI" data-context="minhas-contas_conta_status"><div font-size="14" width="auto" class="Alert__StyledAlert-huwm74-0 cOBlGy"><div></div><div>Vencida há <strong data-context="minhas-contas_conta_tempo-vencimento">368 dias</strong></div></div></div></div></div></div><div class="Row styled__Row-sc-13w6d15-0 fKsxZO"></div><div class="col styled__Col-sc-4ph28m-0 kGpLSX"><div class="Row styled__Row-sc-13w6d15-0 gPFeBI"><div class="col styled__Col-sc-4ph28m-0 lnnClR"><button id="baixa_pdf_210888-2" data-context="minhas-contas_produto_conta_btn-ver-boleto" font-size="0.875rem" width="100%" class="styled__Button-sc-6mz6kj-0 EOEkK">Baixar conta em PDF</button></div></div></div><div class="Row styled__Row-sc-13w6d15-0 gPFeBI"></div><div class="Row styled__Row-sc-13w6d15-0 fKsxZO"></div><div class="col styled__Col-sc-4ph28m-0 jtUyYJ"><button id="exibe_codigo_de_barras_210888-2" data-context="minhas-contas_conta_codigo-barras_btn-ver-codigo-barras" font-size="0.875rem" width="100%" class="styled__Button-sc-6mz6kj-0 gMrMBo">VER CÓDIGO DE BARRAS <span class="sc-1o2smz3-2 dAGdGd styled__Arrow-tuh5ii-0 dYwLxl"><svg width="12px" height="8px" viewBox="0 0 12 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><polygon id="chevron" points="7.41 8 12 12.9446694 16.59 8 18 9.52226721 12 16 6 9.52226721"></polygon></defs><g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Interface/Seta-expandir" transform="translate(-6.000000, -8.000000)"><mask id="mask-2" fill="white"><use xlink:href="#chevron"></use></mask><use id="Seta-expandir" fill="#D82482" fill-rule="nonzero" xlink:href="#chevron"></use></g></g></svg></span></button></div></div><div height="260" class="sc-1o2smz3-6 dJMXeH Collapsible__CollapsibleContainer-sc-12167wd-0 gksWIz" width="100%" open=""><div class="sc-1o2smz3-7 EuVAO"><div class="col styled__Col-sc-4ph28m-0 feSHva"><div class="Row styled__Row-sc-13w6d15-0 bVFhjc"><svg width="648px" height="80px" x="0px" y="0px" viewBox="0 0 648 80" xmlns="http://www.w3.org/2000/svg" version="1.1" style="transform: translate(0,0)"><rect x="0" y="0" width="648" height="80" style="fill:#ffffff;"></rect><g transform="translate(0, 0)" style="fill:#000000;"><rect x="0" y="0" width="1.6" height="80"></rect><rect x="3.2000000000000006" y="0" width="1.6" height="80"></rect><rect x="6.4" y="0" width="4.800000000000001" height="80"></rect><rect x="12.8" y="0" width="1.6" height="80"></rect><rect x="16" y="0" width="1.6" height="80"></rect><rect x="22.400000000000002" y="0" width="4.800000000000001" height="80"></rect><rect x="28.8" y="0" width="1.6" height="80"></rect><rect x="35.2" y="0" width="1.6" height="80"></rect><rect x="38.400000000000006" y="0" width="4.800000000000001" height="80"></rect><rect x="44.8" y="0" width="4.800000000000001" height="80"></rect><rect x="54.4" y="0" width="1.6" height="80"></rect><rect x="60.800000000000004" y="0" width="1.6" height="80"></rect><rect x="64.00000000000001" y="0" width="1.6" height="80"></rect><rect x="67.2" y="0" width="1.6" height="80"></rect><rect x="70.4" y="0" width="4.800000000000001" height="80"></rect><rect x="80.00000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="89.60000000000001" y="0" width="1.6" height="80"></rect><rect x="92.80000000000001" y="0" width="1.6" height="80"></rect><rect x="96.00000000000001" y="0" width="1.6" height="80"></rect><rect x="99.2" y="0" width="4.800000000000001" height="80"></rect><rect x="108.80000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="118.4" y="0" width="1.6" height="80"></rect><rect x="121.60000000000001" y="0" width="1.6" height="80"></rect><rect x="124.80000000000001" y="0" width="1.6" height="80"></rect><rect x="128" y="0" width="4.800000000000001" height="80"></rect><rect x="137.6" y="0" width="4.800000000000001" height="80"></rect><rect x="147.20000000000002" y="0" width="1.6" height="80"></rect><rect x="150.4" y="0" width="1.6" height="80"></rect><rect x="153.60000000000002" y="0" width="1.6" height="80"></rect><rect x="160" y="0" width="4.800000000000001" height="80"></rect><rect x="166.4" y="0" width="4.800000000000001" height="80"></rect><rect x="176.00000000000003" y="0" width="1.6" height="80"></rect><rect x="179.20000000000002" y="0" width="1.6" height="80"></rect><rect x="185.6" y="0" width="4.800000000000001" height="80"></rect><rect x="192.00000000000003" y="0" width="1.6" height="80"></rect><rect x="195.2" y="0" width="4.800000000000001" height="80"></rect><rect x="204.8" y="0" width="1.6" height="80"></rect><rect x="208" y="0" width="4.800000000000001" height="80"></rect><rect x="214.4" y="0" width="1.6" height="80"></rect><rect x="217.60000000000002" y="0" width="1.6" height="80"></rect><rect x="224" y="0" width="4.800000000000001" height="80"></rect><rect x="233.60000000000002" y="0" width="1.6" height="80"></rect><rect x="236.8" y="0" width="4.800000000000001" height="80"></rect><rect x="246.4" y="0" width="1.6" height="80"></rect><rect x="249.60000000000002" y="0" width="1.6" height="80"></rect><rect x="252.8" y="0" width="1.6" height="80"></rect><rect x="256" y="0" width="4.800000000000001" height="80"></rect><rect x="265.6" y="0" width="4.800000000000001" height="80"></rect><rect x="272" y="0" width="4.800000000000001" height="80"></rect><rect x="281.59999999999997" y="0" width="1.6" height="80"></rect><rect x="284.8" y="0" width="1.6" height="80"></rect><rect x="288" y="0" width="1.6" height="80"></rect><rect x="294.4" y="0" width="1.6" height="80"></rect><rect x="297.6" y="0" width="4.800000000000001" height="80"></rect><rect x="304" y="0" width="1.6" height="80"></rect><rect x="310.4" y="0" width="1.6" height="80"></rect><rect x="313.6" y="0" width="4.800000000000001" height="80"></rect><rect x="323.2" y="0" width="4.800000000000001" height="80"></rect><rect x="332.8" y="0" width="1.6" height="80"></rect><rect x="336" y="0" width="4.800000000000001" height="80"></rect><rect x="342.4" y="0" width="1.6" height="80"></rect><rect x="345.6" y="0" width="1.6" height="80"></rect><rect x="352" y="0" width="4.800000000000001" height="80"></rect><rect x="361.6" y="0" width="1.6" height="80"></rect><rect x="364.8" y="0" width="4.800000000000001" height="80"></rect><rect x="374.4" y="0" width="1.6" height="80"></rect><rect x="377.6" y="0" width="1.6" height="80"></rect><rect x="380.8" y="0" width="4.800000000000001" height="80"></rect><rect x="387.2" y="0" width="1.6" height="80"></rect><rect x="393.6" y="0" width="1.6" height="80"></rect><rect x="396.8" y="0" width="4.800000000000001" height="80"></rect><rect x="406.4" y="0" width="1.6" height="80"></rect><rect x="409.6" y="0" width="4.800000000000001" height="80"></rect><rect x="416" y="0" width="1.6" height="80"></rect><rect x="419.2" y="0" width="1.6" height="80"></rect><rect x="425.6" y="0" width="4.800000000000001" height="80"></rect><rect x="435.2" y="0" width="1.6" height="80"></rect><rect x="438.4" y="0" width="1.6" height="80"></rect><rect x="441.6" y="0" width="4.800000000000001" height="80"></rect><rect x="448" y="0" width="1.6" height="80"></rect><rect x="454.40000000000003" y="0" width="4.800000000000001" height="80"></rect><rect x="464" y="0" width="1.6" height="80"></rect><rect x="467.2" y="0" width="1.6" height="80"></rect><rect x="470.4" y="0" width="1.6" height="80"></rect><rect x="473.6" y="0" width="4.800000000000001" height="80"></rect><rect x="483.2" y="0" width="4.800000000000001" height="80"></rect><rect x="492.8" y="0" width="1.6" height="80"></rect><rect x="496" y="0" width="1.6" height="80"></rect><rect x="502.4" y="0" width="1.6" height="80"></rect><rect x="505.6" y="0" width="4.800000000000001" height="80"></rect><rect x="515.2" y="0" width="4.800000000000001" height="80"></rect><rect x="521.6" y="0" width="1.6" height="80"></rect><rect x="524.8000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="531.2" y="0" width="1.6" height="80"></rect><rect x="537.6" y="0" width="1.6" height="80"></rect><rect x="544" y="0" width="1.6" height="80"></rect><rect x="547.2" y="0" width="4.800000000000001" height="80"></rect><rect x="553.6" y="0" width="4.800000000000001" height="80"></rect><rect x="560" y="0" width="1.6" height="80"></rect><rect x="563.2" y="0" width="1.6" height="80"></rect><rect x="569.6" y="0" width="1.6" height="80"></rect><rect x="576.0000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="582.4" y="0" width="1.6" height="80"></rect><rect x="585.6" y="0" width="1.6" height="80"></rect><rect x="588.8000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="598.4000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="608" y="0" width="1.6" height="80"></rect><rect x="611.2" y="0" width="1.6" height="80"></rect><rect x="614.4" y="0" width="1.6" height="80"></rect><rect x="617.6000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="627.2" y="0" width="4.800000000000001" height="80"></rect><rect x="636.8000000000001" y="0" width="1.6" height="80"></rect><rect x="640.0000000000001" y="0" width="4.800000000000001" height="80"></rect><rect x="646.4000000000001" y="0" width="1.6" height="80"></rect></g></svg></div><p align="center" font-weight="Bold" lineheight="1.5" type="p" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-size="16" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 iWZvwv">84600000000-6  99880113224-7  51558980900-0  00516100000-4</p></div><div class="Row styled__Row-sc-13w6d15-0 kHQmEI"><div class="sc-1o2smz3-9 jjdcZL Alert__StyledAlert-huwm74-0 cOBlGy" font-size="14" width="auto"><div></div><div><p class="sc-1o2smz3-3 kPGwia Text__TextStyle-fp0yjz-0 beCits" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" font-size="16" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" lineheight="1em" letter-spacing="normal" whitespace="initial" maxwidth="initial">Lembre-se que esta conta está cadastrada em Débito Automático.<br>Se realizar o pagamento agora, você deverá entrar em contato com seu banco pra retirar o débito programado.</p></div></div></div><div class="sc-1o2smz3-8 bdzhlP styled__Row-sc-13w6d15-0 SpKwt"><div><button id="envia_codigo_de_barras_210888-2" data-context="minhas-contas_conta_codigo-barras_btn-enviar" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z"></path></svg> Enviar</button><div class="modal styled__Modal-a94357-0 fQRtzL"><aside class="overlay styled__Overlay-gtv01n-0 joIHPo"></aside><div radius="4" display="flex" direction="column" width="100%" height="auto" cursor="initial" order="0" class="Modal__Container-sc-13j9751-1 cbeGrw Container__ContainerStyle-sc-1iqy2ia-0 dVRtOm" style="max-width: 500px; display: flex; flex: 1 1 0%;"><button class="fechar styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg width="30" height="30" viewBox="0 0 30 30"><path fill="#9B9B9B" fill-rule="evenodd" d="M13.106 15.09L8.227 19.85l1.625 2.035 5.119-4.976 5.099 4.976 1.882-1.83-5.109-4.966 5.109-4.967-1.882-1.83-5.1 4.976-5.118-4.976-1.625 2.035 4.879 4.762zM15 30C6.716 30 0 23.284 0 15 0 6.716 6.716 0 15 0c8.284 0 15 6.716 15 15 0 8.284-6.716 15-15 15z"></path></svg></button><div class="Row styled__Row-sc-13w6d15-0 gPFeBI" data-context="popup_enviar-codigo-barras" style="width: 100%;"><div class="col styled__Col-sc-4ph28m-0 bWdzYK"><div class="Row styled__Row-sc-13w6d15-0 gPFeBI"><h2 class="sc-1h9tg9u-1 ieQsBc Title__TitleStyle-sc-5b4olk-0 gZiyVB" font-weight="Regular" width="100%">Enviar código de barras</h2></div><div class="Row styled__Row-sc-13w6d15-0 cXZsiu"><div class="col styled__Col-sc-4ph28m-0 cEyrnf"><label class="progress-bar styled__Radio-sc-13c6bcq-0 jIgdvS" data-context="popup_enviar-codigo-barras_input-radio_forma-envio" id="envio_email"><input type="checkbox" checked=""><span></span><p font-size="18px" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" lineheight="1em" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 gTxJFk">&nbsp;E-mail</p></label></div><div class="Row styled__Row-sc-13w6d15-0 fKsxZO"></div><div class="col styled__Col-sc-4ph28m-0 cEyrnf"><label class="progress-bar styled__Radio-sc-13c6bcq-0 jIgdvS" data-context="popup_enviar-codigo-barras_input-radio_forma-envio" id="envio_sms"><input type="checkbox"><span></span><p font-size="18px" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" lineheight="1em" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 gTxJFk">&nbsp;SMS pra Celular Oi</p></label></div><div class="col styled__Col-sc-4ph28m-0 cEyrnf"></div></div><div class="Row styled__Row-sc-13w6d15-0 gPFeBI"><div class="col styled__Col-sc-4ph28m-0 cKjXbt"><fieldset class="styledFieldset-sc-1r2we57-0 jBoAvV"><input class="sc-1h9tg9u-0 dFDlQp styledInput__Input-sc-1apvofq-0 bkjwCX" id="informe_email" data-context="popup_enviar-codigo-barras_input-text_email" placeholder="Digite seu e-mail" maxlength="50" value=""><div class="sc-1h9tg9u-0 dFDlQp styledMessage-d8kpbw-0 gAaQEw"></div></fieldset></div></div><div class="Row styled__Row-sc-13w6d15-0 kRKEGz"><div class="col styled__Col-sc-4ph28m-0 cKjXbt"><button disabled="" id="submit_envio" data-context="popup_enviar-codigo-barras_input-submit" font-size="0.875rem" width="100%" class="styled__Button-sc-6mz6kj-0 crrbD">ENVIAR</button></div></div></div></div></div></div></div><button data-context="minhas-contas_conta_codigo-barras_btn-copiar" id="copia_codigo_de_barras_210888-2" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z"></path></svg> Copiar código</button><button data-context="minhas-contas_conta_codigo-barras_btn-baixar-pdf" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"></path></svg> Baixar PDF</button><button id="imprime_fatura_210888-2" data-context="minhas-contas_conta_codigo-barras_btn-imprimir" class="sc-1o2smz3-5 gzODBO styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg fill="#D82482" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg> Imprimir</button></div></div></div></div><div><div class="modal styled__Modal-a94357-0 fQRtzL"><aside class="overlay styled__Overlay-gtv01n-0 joIHPo"></aside><div radius="4" display="flex" direction="column" width="100%" height="auto" cursor="initial" order="0" class="Modal__Container-sc-13j9751-1 cbeGrw Container__ContainerStyle-sc-1iqy2ia-0 dVRtOm"><button class="fechar styled__Button-sc-6mz6kj-0 EOEkK" font-size="0.875rem" width="100%"><svg width="30" height="30" viewBox="0 0 30 30"><path fill="#9B9B9B" fill-rule="evenodd" d="M13.106 15.09L8.227 19.85l1.625 2.035 5.119-4.976 5.099 4.976 1.882-1.83-5.109-4.966 5.109-4.967-1.882-1.83-5.1 4.976-5.118-4.976-1.625 2.035 4.879 4.762zM15 30C6.716 30 0 23.284 0 15 0 6.716 6.716 0 15 0c8.284 0 15 6.716 15 15 0 8.284-6.716 15-15 15z"></path></svg></button><div class="sc-1o2smz3-1 gwBrau styled__Row-sc-13w6d15-0 gCsrNl"><div font-size="14" width="auto" class="Alert__StyledAlert-huwm74-0 cOBlGy"><div><i size="20" width="auto" height="auto" transform="initial" class="Icon__StyledIcon-t66fqd-0 ilQPJq"><svg viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg"><g fill="#f8562c"><path d="M15,0 C6.72,0 0,6.72 0,15 C0,23.28 6.72,30 15,30 C23.28,30 30,23.28 30,15 C30,6.72 23.28,0 15,0 Z M16.5,22.5 L13.5,22.5 L13.5,19.5 L16.5,19.5 L16.5,22.5 Z M16.5,16.5 L13.5,16.5 L13.5,7.5 L16.5,7.5 L16.5,16.5 Z"></path></g></svg></i></div><div><p color="#222" type="p" align="left" font-family="Simplon, OiTextRegular, simplon_bpregular, sans-serif" font-weight="Regular" font-size="16" fontcolor="#222222" themecolor="dark" margin="0" padding="0" width="100%" height="auto" lineheight="1em" letter-spacing="normal" whitespace="initial" maxwidth="initial" class="Text__TextStyle-fp0yjz-0 beCits">Ocorreu um erro ao baixar o arquivo.<br>Tente novamente mais tarde.</p></div></div></div></div></div></div></div>

共有1个答案

任昊阳
2023-03-14

我将演示如何进行,但问题可能是selenium根据元素类型不总是正确返回isDisplayed()。

public WebElement getFirstVisibleElement(List<WebELement> elements) {
    for (WebElement ele : elements)
        if (ele.isEnabled() && ele.isDisplayed())
            return ele;
    return null;
}

检查网页元素是否显示的更可靠的方法是检查其尺寸(高度和宽度)。如果它们都是零,则不显示。

public WebElement getFirstVisibleElement(List<WebELement> elements) {
    for (WebElement ele : elements)
        if (ele.isEnabled() && ele.getSize().getHeight() > 0 && ele.getSize().getWidth() > 0 )
            return ele;
    return null;
}
 类似资料:
  • 问题内容: 因此,页面充满了很多类似的属性,例如下面的两个元素。例子: 我正在使用PageObject和PageFactory来获取元素,并将它们放入这样的数组中: 问题是这样的:我需要单击这些类似的按钮之一,而不使用索引( 因为事实证明,要维护它很麻烦 )。我想到了一种方法,我可以收集列表中的所有webElement并返回显示在屏幕上的单个webElement(我乐于接受新想法),所以这是我尝试

  • 问题内容: 我想遍历一个webelements列表并从每个元素中返回文本,但是我只从第一个元素而不是从其他标记内的其余元素中获取文本,然后存在存在该循环的代码 这是我要从中提取文本的HTML代码的一部分: 这是Pyhton代码: 问题答案: 一直在我的脸上,这将打印每个元素的文本,很高兴我能发现

  • 本文向大家介绍Ajax返回的json遍历取值并显示到前台的方法,包括了Ajax返回的json遍历取值并显示到前台的方法的使用技巧和注意事项,需要的朋友参考一下 使用$.each(data,function(i,n){}); 可以用n.字段,取到想要的值。 然后将item打入table里 以上这篇Ajax返回的json遍历取值并显示到前台的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也

  • 问题 你有一个HTML文档要从中提取数据,并了解这个HTML文档的结构。 方法 将HTML解析成一个Document之后,就可以使用类似于DOM的方法进行操作。示例代码: File input = new File("/tmp/input.html"); Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/"); Elem

  • 本文向大家介绍Django使用HttpResponse返回图片并显示的方法,包括了Django使用HttpResponse返回图片并显示的方法的使用技巧和注意事项,需要的朋友参考一下 做了一个关于Django的小案例,想要在网页中显示图片,直接在img标签的src属性写图片的路径是不能显示的,查询资料发现在Django中使用图片这类的资源相当繁琐需要进行一定D的配置,摸索了一会没有整明白,想到了写

  • 问题内容: 我有一个返回JSON的MVC控制器。我想使用jQuery读取/获取JSON并遍历JSON项目/行。 基本上,我正在阅读一堆评论,然后逐一显示评论。 有人有代码示例吗? 我正确地获取了json。请参阅下面的返回数据。 谢谢 编辑: 如何循环这些由控制器返回的json?我需要循环3次,然后对于每一行,我需要访问该行中的所有键和值。 问题答案: 第一个问题的答案是允许Json在GET中工作。