【问题标题】:How to access a button which changes states如何访问更改状态的按钮
【发布时间】:2020-05-25 18:47:17
【问题描述】:

我有一个按钮,它有两种状态——启用和禁用

启用状态: <button type="button" class="btt-download-csv site-toolbar-menu-button icon-download no-icon-margins ng-isolate-scope" title="Download CSV" rc-download-csv="" current-segment-path="all" ng-disabled="noCustomers || loadingCustomers" ng-show="!deleteModeEnabled"></button>

禁用状态: <button type="button" class="btt-download-csv site-toolbar-menu-button icon-download no-icon-margins ng-isolate-scope" title="Download CSV" rc-download-csv="" current-segment-path="all" ng-disabled="noCustomers || loadingCustomers" ng-show="!deleteModeEnabled" disabled=""></button>

注意代码末尾的disabled="" 字样。如何指定我要单击未禁用的按钮?

我使用以下 css 选择器,但它不关心按钮的状态:

"button.btt-download-csv.site-toolbar-menu-button.icon-download.no-icon-margins.ng-isolate-scope"

【问题讨论】:

    标签: python css selenium


    【解决方案1】:

    您可以使用css_selector 来定位没有特定属性的元素

    driver.find_element_by_css_selector('[title="Download CSV"]:not([disabled])')
    

    xpath

    driver.find_element_by_xpath('//button[@title="Download CSV"][not(@disabled)])
    

    【讨论】:

      【解决方案2】:

      如果要禁用按钮,只需添加属性disabled

      普通按钮: <button type="button"></button>

      使用 css 访问此按钮: button {}

      禁用按钮: <button type="button" disabled></button>

      使用 css 访问此按钮: button[disabled] {}

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-20
        相关资源
        最近更新 更多