Protractor 无法检查按钮是否已禁用或不在量角器中

Protractor 无法检查按钮是否已禁用或不在量角器中,protractor,Protractor,当我试图检查一个按钮是否被禁用时,它会给出一个错误 AssertionError: expected { Object (browser_, then, ...) } to be true 我正在使用量角器cucumber版本5.2.2、cucumber版本3.2.0和chai库 我的代码是 expect(element(by.css('.frx-btn-login')).getAttribute('disabled')).to.be.true; 当我尝试使用getText()方法获取字符串

当我试图检查一个按钮是否被禁用时,它会给出一个错误

AssertionError: expected { Object (browser_, then, ...) } to be true
我正在使用量角器cucumber版本5.2.2、cucumber版本3.2.0和chai库

我的代码是

expect(element(by.css('.frx-btn-login')).getAttribute('disabled')).to.be.true;

当我尝试使用getText()方法获取字符串值时,它也会给出这种类型的错误。

您需要以如下所示的正确方式使用断言

expect(element(by.css('.frx-btn-login')).getAttribute('disabled')).toBe('true')
此外,要检查某项功能是否已启用或禁用,应使用isEnabled()

像这样-
expect(元素(by.css('.frx btn login').isEnabled()).toBe([true | false]);

或者,如果您正在使用PageObject,请按如下方式操作:

//页面类

this.yourElement = element(by.css('.frx-btn-login');

this.checkElement = function () {

    return this.yourElement.isEnabled();
}
};
//规格等级:

  page.checkElement().then(function (val) {
      expect(val).toBe([true|false]);
    });
试试看:

return expect(element(by.css('.frx-btn-login')).getAttribute('disabled')).to.eventually.equals('true');

我尝试使用expect(元素by.css('.frx btn login')).getAttribute('disabled')).to.be.true;和expect(元素by.css('.frx btn login')).isEnabled().to.be.true;但它给出了相同的错误。当我控制台它时,返回的是对象而不是值。@Rose请仔细检查您是否又犯了相同的错误。您不应该使用.to.be.true,而应该使用expect(element(by.css('.frx btn login').isEnabled()).toBe([true | false]),仔细阅读我的答案。这会有所帮助