protractor icon indicating copy to clipboard operation
protractor copied to clipboard

isEnabled() assertion returns incorrect value for disabled <label> element

Open mcalthrop opened this issue 12 years ago • 12 comments

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.

mcalthrop avatar Mar 04 '14 22:03 mcalthrop

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

juliemr avatar Mar 05 '14 00:03 juliemr

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

mcalthrop avatar Mar 05 '14 10:03 mcalthrop

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'

demisx avatar Jun 10 '14 18:06 demisx

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>.

joshuakeel avatar Oct 13 '14 20:10 joshuakeel

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.

awerlang avatar Nov 14 '14 21:11 awerlang

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.

screen shot 2015-01-20 at 3 53 28 pm

This test passes: screen shot 2015-01-20 at 3 55 59 pm

A workaround may be to use ng-disabled.

adamjaffeback avatar Jan 20 '15 23:01 adamjaffeback

I think, as mentioned above, this is webdriver working as intended.

juliemr avatar Jan 27 '15 22:01 juliemr

Thanks @adam-back ! your reply saved my a lot of time!! thanks!!

bmsoko avatar May 15 '15 22:05 bmsoko

No problem! Glad to help.

adamjaffeback avatar May 15 '15 23:05 adamjaffeback

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 avatar Jun 19 '15 19:06 dmitroboltenko

@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.

awerlang avatar Jun 19 '15 19:06 awerlang

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 ?

ItsSarronya avatar Dec 13 '17 09:12 ItsSarronya