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

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.


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

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

The previous example of


Will not work for checking if something is enabled.

You should use


to accurately verify if something is enabled/disabled.

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

I want to add that @TaylorRose‘s answer (the most voted answer) is very good and thank him for that.

// passes when the button does not have 'disabled' attribute

However when I tried to run this I got an error:

 Error: TSError: ⨯ Unable to compile TypeScript e2e/specs/element.e2e-spec.ts: 
  Argument of type 'false' is not assignable to parameter of type 'Expected<Promise<boolean>>'.

There are multiple solutions to this issue and here are two of them:

1.Cast your expect to type ‘any’


2.Add @types/jasminewd2 to your package json (and run ‘npm install’ of course) (thanks to [email protected]github)

 "devDependencies": {
    "@types/jasminewd2": "2.0.6",

And then no more errors from typescript and it solves this problem.
P.s. Version 2.0.6 is the latest as of writing this post and the magic version could be different for your case.

So this is addition to the most voted answer if anybody here is having this issue.

Read More:   When is it safe to call URL.revokeObjectURL?

When using “getAttribute(‘disabled’).toEqual(‘true’) ” did not work
I used className instead, to complete my test, as the classNames changed when disabled.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Similar Posts