isEnabled() assertion returns incorrect value for disabled <label> element
I just discovered what I am pretty sure is a bug.
The markup I am using looks like this:
<label id='blah-label-id' disabled="disabled" data-ng-click="handleClick()">
<input type="radio">blah</label>
The Protractor assertion I am using looks like this:
expect(element(by.id('blah-label-id')).isEnabled()).toBe(false);
However, the above assertion fails.
When I test it to see the result of isEnabled(), it returns true, when you'd expect it to return false.
I have tested this by calling getAttribute('disabled') on the same element – it returns 'true' (as a string, not a boolean value).
Note that in the same suite of tests, I am successfully using the isEnabled() assertion on <input type="range">, <input type="text"> and <button> elements.
Interesting. isEnabled is a direct webdriver function, so this may be a bug with webdriver - or maybe it was not intended to work with labels. Which browser are you testing on?
FYI the wire protocol for 'enabled' doesn't seem to specify: https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/enabled
I'm using Chrome 33.0.1750.117 on OSX 10.9.2.
It's a bit of a nuisance, because I spent a lot of time thinking that the test had failed.
But I have the workaround of using this:
expect(element(by.id('blah-label-id')).getAttribute('disabled')).toBe('true')
I have a similar issue with a disabled link button. For this DOM element:
<a ng-disabled="isDisabled()" class="btn ng-isolate-scope" ng-click="onClick()" ng-transclude="" id="svapp-previous-slide-link" on-click="showPreviousSlide()" disabled-when="isFirstSlide()" disabled="disabled">
<i class="fa fa-lg fa-caret-left ng-scope"></i><span class="ng-scope">Previous
</span></a>
the following test fails with Expected true to be false.
expect(element(By.id("svapp-previous-slide-link")).isEnabled()).toBe false
For now, using similar workaround as @mcalthrop mentioned above:
expect(element(By.id("svapp-previous-slide-link")).getAttribute('disabled')).toEqual 'true'
Just to add a "me too" here, I'm having the same issue as @demisx, just on a <span> instead of an anchor. I solved my issue by changing to a <button>.
Certainly this behavior is not convenient, but I think it is a correct implementation of HTML 5 specs.
See, a and span doesn't have a disabled attribute.
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
- https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
If getAttribute() works, it must be because the way angular implements directives.
As a personal note, these abstractions brought to us by frameworks like bootstrap may hide such subtleties, but we must be aware of.
In my case, I have a variable set on the scope which is used with ng-disabled to set the disabled attribute.
I'm running Chrome Version 39.0.2171.99 (64-bit) and OS X10.10.

This test passes:

A workaround may be to use ng-disabled.
I think, as mentioned above, this is webdriver working as intended.
Thanks @adam-back ! your reply saved my a lot of time!! thanks!!
No problem! Glad to help.
This trouble sounds strange. Looks like it happened because attribute disabled has string value instead of boolean, and WebDriver expect boolean. Correct me if I'm wrong. According to HTML 5 standards this attribute should be boolean http://www.w3.org/TR/html5/forms.html#concept-fe-disabled. Does Angula make this attribute string? Another question why Chrome displays this element correct as disabled? My guess if it works in another browsers the same way it works in Chrome. Probably WebDriver should update their behavior.
@dmitroboltenko you're refering to an attribute shared by form controls (under 4.10.19 Attributes common to form controls). label isn't a form control though.
also, see my answer above.
When the button is disabled, the below is the web structure, Save Button Disabled- "" Similary when the button is enabled, the below is the web structure,
Save Button Enabled - "" if this is the case, when i do a getattribute of disabled, a null is returned. How do I verify in protractor if the button is disabled or enabled for a certain condition ?