Selenium modal Xpath找不到

时间:2015-04-22 09:12:20

标签: html selenium xpath

我需要选择此输入

`(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>

2 个答案:

答案 0 :(得分:1)

按名称选择:

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

答案 1 :(得分:0)

由Xpath选择

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