(Protractor) Checking whether an input is disabled on click?

rabishah picture rabishah · Feb 18, 2014 · Viewed 39.4k times · Source

I have two input fields, Username and Password and a spinner button. When i click on this spinner button these two input fields get disabled and I am redirected to another page. I am writing an end-to-end testing to check whether these input fields are disabled.

element(by.model('username')).sendKeys('rabi');                   
element(by.model('password')).sendKeys('rabi');                   

/* click on spin button */
spinBtn = element(by.className('call-to-action'));                               
spinBtn.click(); 

/* check if input is disabled */
var loginInput = element(by.id('login-username'));                               
expect(loginInput.isEnabled()).toBe(false);

Answer

Taylor Rose picture Taylor Rose · May 15, 2014

The previous example of

expect(loginInput.getAttribute('disabled')).toEqual('disabled');

Will not work for checking if something is enabled.

You should use

expect(loginInput.isEnabled()).toBe([true|false]);

to accurately verify if something is enabled/disabled.

If that isn't working for you, there's probably something else going on.