我在 Selenium 中选择这个项目是这样的:
filter_panel = self.browser.find_element_by_class_name('panel-filters')
filter_onair = filter_panel.find_element_by_css_selector("div.form-group.mod-toggle.js-onair[data-toggle='tooltip'][data-placement='top']")
但是如果这个项目有 disabled
类,我如何在 Selenium 中测试?
最佳答案
你可以试试
assert 'disabled' in filter_onair.get_attribute('class').split()
或者您可以尝试使用 .disabled
扩展 CSS 选择器:
filter_onair = filter_panel.find_element_by_css_selector("div.form-group.mod-toggle.js-onair.disabled[data-toggle='tooltip'][data-placement='top']")
如果您得到 NoSuchElementException
,则所需选择器中没有包含 "disabled"
类名的元素
关于python - Selenium 测试 CSS 类是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52933556/