启用或禁用按钮:Webdriver如何决定? [英] Button enabled or disabled : How does webdriver decide?

查看:77
本文介绍了启用或禁用按钮:Webdriver如何决定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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如何决定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆