HTML of the button:
<button 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.
CodePudding user response:
There is a function in WebDriver called is_enabled
which returns true if the element is enabled, else it returns 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
CodePudding user response:
"disabled"
is not a property, but attribute so you need to replace
element.get_property('disabled')
with
element.get_attribute('disabled')
CodePudding user response:
disabled Attribute
The disabled
attribute is a boolean attribute which specifies that the element should be disabled unless some prerequisites are met. A disabled
element is unusable. Generally the disabled
attribute can be set to keep a user from using the element until some other condition has been met e.g. selecting a checkbox, radio button, etc.
This usecase
As per the given HTML:
<button disabled type="button" xpath="1">submit Button</button>
To probe if the <button>
is disabled you can perform the following test:
try:
self.element.findElement(By.xpath, '//button[text()="submit Button"][disabled]')
print("button is disabled")
except NoSuchElementException:
print("button wasn't disabled")