Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify if a button is enabled and disabled in Webdriver Python?

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'
like image 482
L P Avatar asked May 06 '14 14:05

L P


5 Answers

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.

like image 186
alecxe Avatar answered Oct 20 '22 11:10

alecxe


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')

like image 9
Nisheeth Avatar answered Oct 20 '22 11:10

Nisheeth


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...
like image 3
nerdwaller Avatar answered Oct 20 '22 10:10

nerdwaller


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*/
like image 2
user3748027 Avatar answered Oct 20 '22 11:10

user3748027


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.

like image 1
pramod_maddu Avatar answered Oct 20 '22 12:10

pramod_maddu