Selenium modal xpath

时间:2015-04-20 12:58:38

标签: html selenium xpath

我需要选择此输入...

(name="BtnNext" value="İLERİ" class="NavigationButtonNextLightBox ")

...在此模式弹出窗口后使用xpath。我无法使用.FindByClass,因为主页中有相同的类,但我需要在(id="__LIGHTBOX__")模态中打开;


<div style="overflow: visible; padding: 0px; width: auto; min-height: 143px; max-height: none; height: auto;" class="ui-dialog-content ui-widget-content" id="__LIGHTBOX__">
    <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">

            <form action="/BillPayment/TransferInfo" method="post">
                <div class="banner clearFix">
                    <h1 class="pageTitle">Fatura Ödeme</h1>
                </div>
                <div class="relatedPeopleContainer clearFix">
                    <div class="topDiv">
                    </div>
                    <div class="relatedPeople clearFix">
                        <table>
                            <tbody>
                                <tr>
                                    <td class="t1">
                                        <img src="Content/banks/bank205.png">
                                    </td>
                                    <td class="t2 SenderReceiverSubmit" rowspan="2" style="cursor: pointer;">
                                        <div class="arrow">
                                        </div>
                                    </td>
                                    <td class="t3">
                                        <img src="Content/company/Turkcell.png">
                                    </td>
                                </tr>
                                <tr>
                                    <td class="t4">
                                        <div class="info right">
                                            <h2 class="NavigationButtonIndex" style="cursor: pointer;" title="Hesabınızı değiştirmek için tıklayınız.">HESABIM
                                <img src="/Content/themes/base/images/change-account.png" alt="" style="height: 20px; vertical-align: text-bottom;">
                                            </h2>

                                            <p class="first">
                                                Beşyüzevler Şube
                                            </p>
                                            <p>
                                                Cari Hesap
                                            </p>
                                            <p>
                                                10136046-1
                                            </p>
                                            <p>
                                                1.256,51 TL
                                            </p>
                                        </div>
                                    </td>
                                    <td class="t6">
                                        <div class="info left">
                                            <h2>TURKCELL
                                            </h2>

                                            <p class="first">
                                                1774862559
                                            </p>
                                            <p>
                                                5303003816
                                            </p>
                                            <p>
                                                23,40 TL
                                            </p>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="bottomDiv">
                    </div>
                </div>
                <div class="amountEntry clearFix">
                    <table class="moneyEditorTable ">
                        <tbody>
                            <tr>
                                <td>
                                    <input class="integerinput " data-val="true" data-val-regex="The field Integer must match the regular expression '[0-9.,]{1,11}'." data-val-regex-pattern="[0-9.,]{1,11}" datavalrequired="" disabled="disabled" id="IntegerInput" name="Amount.Integer" onkeyup=";" value="23" type="text"></td>
                                <td class="spanTd">
                                    <span class="currency ">,</span>
                                </td>
                                <td>
                                    <input maxlength="2" class="decimalinput  " data-val="true" data-val-range="The field Decimal must be between 0 and 99." data-val-range-max="99" data-val-range-min="0" datavalrequired="" disabled="disabled" id="DecimalInput" name="Amount.Decimal" onkeypress="return BOA.Web.Validation.NumericControl(event);" onkeyup=";BOA.Web.Validation.DecimalPoint(event, $(this));" onpaste="BOA.Web.Validation.NumericEditorPaste(event, $(this));" value="40" type="text"></td>
                                <td class="spanTd">
                                    <span class="currency ">TL</span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <input id="Amount_FECCode" name="Amount.FECCode" value="TL" type="hidden">

                    <div class="Error clearFix">
                        <span class="field-validation-valid" data-valmsg-for="Amount" data-valmsg-replace="true"></span>
                    </div>
                </div>
                <table class="popupButtonArea">
                    <tbody>
                        <tr>
                            <td class="left">
                                <input name="BtnPrev" value="GERİ" class="NavigationButtonPrev " type="button">
                            </td>
                            <td class="right">
                                <input name="BtnNext" value="İLERİ" class="NavigationButtonNextLightBox " type="button">
                                <input name="FromStep" value="TransferInfo" type="hidden">
                            </td>
                        </tr>
                    </tbody>
                </table>
                <input name="__RequestVerificationToken" value="jzI4c0v-PPC60xzaY8B2FDiCLYmHwCCtQsYv7UbBIMgnBWFeEpJoLLMDgf4LGl24WxhfizGlsqEJdjhywzgNHT785XHRzmwcU2qDyaQfSh6SajD8WKCAEq2L8CejPMJ65QL45A2" type="hidden">
            </form>
        </div>
        <div>
            <img src="/Content/themes/base/images/popup-bg-sub.png">
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:1)

您可以尝试通过以下xpath查找元素:

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

在xpath上方尝试查找ID为<div>的{​​{1}},然后从名称属性等于LIGHTBOX的{​​{1}}获取<div>元素中查找属性包含<input>

答案 1 :(得分:1)

我不确定我在这里遗漏了什么,但是什么阻止你选择名字?

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