javascript-使用WebElement.isEnabled()启用了禁用的锚点返回
作者:互联网
由于某些原因,即使在禁用的html锚标记上,elmFinder.isEnabled()也会解析为true.
我已经设置了test site to prove this.
当IMHO不应该进行以下量角器测试失败
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
解决方法:
will generally return true for everything but disabled input elements.
所以我想想,解决方法是使用否定elm.getAttribute(‘disabled’)代替elm.isEnabled()
it('link should now be disabled', function() {
expect(linkElm.getAttribute('disabled')).toBeTruthy();
});
标签:angularjs,selenium,selenium-webdriver,protractor,javascript 来源: https://codeday.me/bug/20191121/2050701.html