如何使用ID和Class的唯一XPath / CSS选择器相同的元素?

时间:2014-12-02 21:01:59

标签: python css xpath selenium-webdriver

我有以下HTML:

<div id="btnCreditCard" class="paymentBtn bitcoin" style="display: none">
    <a class="button button-primary button-override has-icon-right" href="javascript:Biz.GlobalShopping.CheckOut.continueToReview(8);">
        <i class="button-icon-left"></i>Continue To Order Review<i class="button-icon-right fa fa-caret-right"></i>
    </a>
</div>

<div id="btnMasterPass" class="paymentBtn masterpass" style="display: none;">
    <a href="javascript:Biz.GlobalShopping.CheckOut.continueToReview(4);" title="MasterPass" style="cursor: pointer;">
        <img src="https://www.mastercard.com/mc_us/wallet/img/en/US/mcpp_wllt_btn_chk_147x034px.png" alt="MasterPass" />
    </a>
</div>

<div id="btnCreditCard" class="paymentBtn npa" style="display: none">
    <a class="button button-primary button-override has-icon-right" href="javascript:Biz.GlobalShopping.CheckOut.continueToReview(5);">
        <i class="button-icon-left"></i>Continue To Order Review<i class="button-icon-right fa fa-caret-right"></i>
    </a>
</div>

<div id="btnCreditCard" class="paymentBtn billlater" style="display: none">
    <a class="button button-primary button-override has-icon-right" href="javascript:Biz.GlobalShopping.CheckOut.continueToReview(6);">
        <i class="button-icon-left"></i>Continue To Order Review<i class="button-icon-right fa fa-caret-right"></i>
    </a>
</div>

我必须选择父级DIV <div id="btnCreditCard" class="paymentBtn billlater" style="display: none">的锚点。我目前使用的xPath是('//*[@id="btnCreditCard"]/a')

1 个答案:

答案 0 :(得分:3)

您可以在XPath中使用and

'//*[@id="btnCreditCard" and @class="paymentBtn billlater"]/a'