问题描述
Selenium Webdriver如何确定按钮是启用还是禁用?我用过isEnabled()两个按钮的方法-一个启用,另一个禁用,但在两种情况下均返回true.除了使用isEnabled()之外,还有其他解决方法吗?
How does selenium webdriver decide whether a button is enabled or disabled? I have used the isEnabled()method for two buttons - one enabled and the other disabled but it returns true for both the cases. Is there a workaround other than using isEnabled() ?
推荐答案
isEnabled()检查在按钮元素上禁用了属性 .如果属性"disabled"不存在,则返回True,因此,如果您从未将此属性添加到禁用按钮,而是将值"disabled"添加到按钮的类,则isEnabled()将始终返回true.
isEnabled() checks for the disabled attribute on the button element. If the attribute "disabled" is not present, it returns True, so if you never add this attribute to disabled buttons and instead add the value "disabled" to the button's class, isEnabled() will always return true.
如果要基于类确定按钮是启用还是禁用,则需要检查是否存在带有"disabled"类的按钮(通过类名,xpath或CSS选择器查找)确定按钮处于什么状态.
If you are determining whether the button is enabled or disabled based on a class, you will need to instead check for the existence of a button with the "disabled" class (find it by class name, xpath, or CSS selector) to decide what state the button is in.
这篇关于启用或禁用按钮:Webdriver如何决定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!