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

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


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.


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' attributeexpect($('#saveChangesBtn').isEnabled()).toBe(true);

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'

expect<any>($('#saveChangesBtn').isEnabled()).toBe(true);

2.Add @types/jasminewd2 to your package json (and run 'npm install' of course) (thanks to aktraore@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.