Reputation: 1846
I tried using the following from another post
driver.find_element_by_name("sub_activate").click().is_enabled()but got this error:
AttributeError: 'NoneType' object has no attribute 'is_enabled'
Upvotes: 21
Views: 150403
Reputation: 93
driver.find_element_by_name("sub_activate").click().is_enabled()
In the above method you have used click() method. Without using it you can verify whether a button is disabled or enabled. It returns a Boolean value.
Upvotes: 1
Reputation: 11
You Can try this one also:
Assert.assertTrue(driver.findElementById("Disable Element Id").isEnabled());
It worked fine in my case.
Upvotes: 0
Reputation: 281
The following works for me:
element = driver.find_element_by_name("sub_activate")
prop = element.get_property('disabled')
print (prop)
>>>> False
Returns 'true' if enabled 'element.get_property('enabled')
Upvotes: 10
Reputation: 31
IWebElement button = driver.FindElement(By.Id("ButtonId"));
Assert.AreEqual(false, button.Enabled); /*Validates whether the button is Disabled*/
Assert.AreEqual(true, button.Enabled); /*Validates whether the button is Enabled*/
Upvotes: 2
Reputation: 1863
You are calling is_enabled()
on the click()
result (None).
Instead, you should first get the element, check if it is_enabled()
then try the click()
(if that is what you are trying to do).
Take a look at the docs for the methods on the webelement
.
is_enabled()
Whether the element is enabled.
click()
Clicks the element.
For example:
elem = driver.find_element_by_id("myId")
if elem.is_enabled():
elem.click()
else:
pass # whatever logic to handle...
Upvotes: 4
Reputation: 473863
You don't need to call click()
. Just find the element and call is_enabled()
on it:
element = driver.find_element_by_name("sub_activate")
print element.is_enabled()
FYI, click()
is a method on a WebElement
, it returns None
.
Upvotes: 42