使用WebElement.isEnabled()启用已禁用的锚点返回

时间:2014-09-07 04:32:46

标签: javascript angularjs selenium selenium-webdriver protractor

出于某种原因elmFinder.isEnabled()即使在已禁用的html锚标记上也会解析为true

我已经设置了test site to prove this

当恕我直言不应

时,以下量角器测试失败
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();
  });
});

输出:

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

1 个答案:

答案 0 :(得分:3)

java bindings docs

找到它
  除了禁用的输入元素之外,

通常会返回true。

所以我想,解决方法是使用+否定elm.getAttribute('disabled')代替elm.isEnabled()

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