[英]How to verify a disabled button using Python Selenium
HTML of the button:按钮的 HTML:
<button class="Button1" disabled type="button" xpath="1">submit Button</button>
def isButtonDisabled(self):
element = self.element.findElement(By.xpath, 'locator')
return element.get_property('disabled')
But this method is not working.但是这种方法行不通。
There is a function in WebDriver called is_enabled
which returns true if the element is enabled, else it returns false.在 WebDriver 中有一个名为
is_enabled
的 function 如果元素启用则返回 true,否则返回 false。
def isButtonDisabled(self):
element = self.element.findElement(By.xpath, 'locator')
return element.is_enabled()
Here's a Reference in the documentation of selenium py这是 selenium py 文档中的参考
"disabled"
is not a property , but attribute so you need to replace "disabled"
不是属性,而是属性,因此您需要替换
element.get_property('disabled')
with和
element.get_attribute('disabled')
The disabled
attribute is a boolean attribute which specifies that the element should be disabled unless some prerequisites are met. disabled
属性是 boolean 属性,它指定除非满足某些先决条件,否则应禁用该元素。 A disabled
element is unusable. disabled
的元素不可用。 Generally the disabled
attribute can be set to keep a user from using the element until some other condition has been met eg selecting a checkbox, radio button, etc.通常,
disabled
属性可以设置为阻止用户使用元素,直到满足某些其他条件,例如选择复选框、单选按钮等。
As per the given HTML:根据给定的 HTML:
<button class="Button1" disabled type="button" xpath="1">submit Button</button>
To probe if the <button>
is disabled you can perform the following test:要探测
<button>
是否被禁用,您可以执行以下测试:
try:
self.element.findElement(By.xpath, '//button[text()="submit Button"][disabled]')
print("button is disabled")
except NoSuchElementException:
print("button wasn't disabled")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.