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

标签 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 的 Anchor <div id="btnCreditCard" class="paymentBtn billlater" style="display: none"> .我目前使用的 xPath 是 ('//*[@id="btnCreditCard"]/a')

最佳答案

您可以在 XPath 中使用 :

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

关于python - 如何通过 ID 和 Class 使用唯一的 XPath/CSS 选择器选择相同的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27258887/

相关文章:

java - Oracle xpath : two select scenarios 的性能

python - Django 模板 : Use different css for pages

Python PyQT 手势

python - 如何根据状态码重试异步 aiohttp 请求

html - 我怎样才能做一个充满屏幕的导航栏?

xml - 如何访问 XSD 断言 XPath 中的父元素?

java - Dom4j XPath 区分 null 或空字符串

python - 从 PyQt 中的 QPushButton 获取文本

html - 如何修复悬停的精度?

jQuery slideDown 动画滞后