Disabled bindings are returned using WebElement.isEnabled ()

elmFinder.isEnabled()

Allows true

even disabled html anchor tags for some reason .

I set up a test site to prove it .

The following Protractor test fails if IMHO shouldn't

describe('isEnabled() should resolve to true on any html element', function() {
  var checkElm = element(by.model('checked'));
  var btnElm = element(by.model('button'));
  var linkElm = element(by.model('link'));

  it('open test page', function() {
    browser.get('http://run.plnkr.co/plunks/oExtzK/');
  });

  it('should be enabled by default: button & link', function() {
    expect(btnElm.isEnabled()).toBeTruthy();
    expect(linkElm.isEnabled()).toBeTruthy();
  });

  it('clicks the checkbox to switch enabled/disabled status', function() {
    checkElm.click();
  });

  it('button should now be disabled', function() {
    expect(btnElm.isEnabled()).toBeFalsy();
  });

  // This fails
  it('link should now be disabled', function() {
    expect(linkElm.isEnabled()).toBeFalsy();
  });
});

      

Output:

Describe: isEnabled() should resolve to true on any html element
 001 - open test page ✔
 002 - should be enabled by default: button & link003 - clicks the checkbox to switch enabled/disabled status004 - button should now be disabled ✔
 005 - link should now be disabled  FAILED!
   Message:    Expected true to be falsy.
   Stacktrace: Error: Failed expectation

      

+3


source to share


1 answer


Found it javas bindings docs

usually returns true for all but disabled input elements.



So, I figured out that the workaround is using + negation elm.getAttribute('disabled')

instead ofelm.isEnabled()

it('link should now be disabled', function() {
  expect(linkElm.getAttribute('disabled')).toBeTruthy();
});

      

+3


source







All Articles