python - 如何访问更改状态的按钮

标签 python css selenium

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

启用状态: <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"

最佳答案

您可以使用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)])

关于python - 如何访问更改状态的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60150594/

相关文章:

python - Django 如何将外键链接到多个表

python - 如何在 PyQt 中编写图像按钮?

java - Try-Catch 无法捕获来自 "System.setProperty"的错误

java - 如何等待一定数量的行?

python - 如何使用许多 OR 替代项来缩短长 XPath 表达式?

Python:将多个十六进制值的字符串转换为整数

python - 无法进入下一页

html - 将那个 ie6/7 错误命名为?

javascript - 如何创建圆环饼图的内边框?

html - 链接标签中的颜色不起作用,但链接标签中的 div 颜色有效?