【问题标题】:Selenium modal Xpath can't LocateSelenium modal Xpath 无法定位
【发布时间】:2016-07-31 21:32:08
【问题描述】:

我需要选择这个输入

`(name="BtnOK" value="TAMAM" class="BoxButtonOK")`

在此模式弹出窗口之后使用xpath。我不能使用.FindByClass,因为主页中有相同的类,但我需要在(id="__LIGHTBOX__") 模态中打开它,当我使用xpath 时,有时它会给我错误“无法定位元素”,有时它会奇怪有效。

这是我的xpath 代码(是的,我已经尝试过wait.until 并且没有任何进展):

//div[contains(@id, 'LIGHTBOX')]//input[@name='BtnNext' and contains(@class, 'NavigationButtonNextLightBox')]

这里是模态的:

<div id="__LIGHTBOX__" style="overflow: visible; padding: 0px; width: auto; min-height: 143px; max-height: none; height: auto;" class="ui-dialog-content ui-widget-content" >
<div class="__BOX__">
    <input name="BtnClose" class="BoxButtonClose" type="button">
    <div>
        <img src="/Content/themes/base/images/popup-bg-top.png">
    </div>
    <div class="popupCapsule clearFix">


        <div class="banner clearFix">
            <h1 class="pageTitle">Fatura Ödeme</h1>
        </div>


        <div class="noteCapsulePopupContainer">
            <div>
                <img src="/Content/themes/base/images/note-capsule-top-success.png">
            </div>
            <div class="noteCapsulePopup">
                <table>
                    <tbody>
                        <tr>
                            <td class="waitingTd"></td>
                            <td>
                                <p id="TransactionFlowNote">
                                    <span>
                                        <span class="important">10177202-1 (Beşyüzevler Şube)</span> adlı hesabımdan <span class="important">27,50 TL</span> tutarındaki <span class="important">5387373484</span> abone numarasına ait <span class="important">TURKCELL</span> faturası kurumuna iletildi, borcunuz kısa süre içerisinde tahsil edilecektir.
                                    </span>
                                </p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div>
                <img src="/Content/themes/base/images/note-capsule-sub.png">
            </div>
        </div>


        <table class="popupButtonArea">
            <tbody>
                <tr>
                    <td class="left"></td>
                    <td class="right">
                        <input name="BtnSlip" value="DEKONT" class="popupOpenLink" style="margin-right: 5px;" href="/Slip/Index/201504220001012380000019284/" type="button"><input name="BtnPeopleAndPlaces" value="İŞLEMİ KAYDET" class="popupOpenLink ButtonWide2" style="margin-right: 5px;" href="/PeopleAndPlaces/SaveTransaction/201504220001012380000019284/1238/False" type="button">
                        <input name="BtnOK" value="TAMAM" class="BoxButtonOK" type="button">
                    </td>
                </tr>
            </tbody>
        </table>



    </div>
    <div>
        <img src="/Content/themes/base/images/popup-bg-sub.png">
    </div>
</div>

【问题讨论】:

标签: html selenium xpath


【解决方案1】:

按名称选择:

WebElement btnNext = driver().findElement(By.name("BtnOK"));

【讨论】:

  • 您能提供更多信息吗?如果您尝试单击所需的按钮,则添加单击操作 btnNext.click()
  • 是的,我需要单击它来关闭模式,并尝试像 .click() 一样仍然没有进展我猜代码在模式弹出之前运行。
【解决方案2】:

由 Xpath 选择

WebElement btnNext = driver().findElement(By.Xpath("//input[@name='BtnOK']"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多