【问题标题】:Protractor : string retrieved in promise of getAttribute() is null量角器:在 getAttribute() 的承诺中检索到的字符串为空
【发布时间】:2016-02-17 23:17:25
【问题描述】:

说我必须验证复选框的状态

element(by.css('input')).getAttribute("checked").then(function(isChecked:string) {
      expect(isChecked).toEqual(pExpected.toString());
    }),

在我的测试中,我验证了默认情况下选中了该复选框。这里一切正常。然后我取消选中复选框

element(by.css('input')).click();

并调用函数来验证复选框是否未选中。这一次,变量isChecked 为空。我也试过了

var cb = element(by.css('input'));
cb .click().then(function(){
  cb .getAttribute("checked").then(function(isChecked:string){
    expect(isChecked).toEqual("false");
  })
});

什么都没有改变。我无法理解这里发生了什么。在此先感谢您的帮助。

【问题讨论】:

  • 您可能想了解属性和属性之间的区别 - 选中的属性要么不存在,要么存在且已被选中。选中的属性为真或假。 (IIRC)
  • @BenjaminGruenbaum 嗨,感谢您的评论,我与元素检查员进行了核对。 “检查”的属性应该是我必须得到的。但是如何使用 Protractor 访问该属性?有什么提示吗?

标签: angularjs selenium-webdriver promise protractor


【解决方案1】:

使用类似- expect(element(by.css('input')).isSelected()).toBeFalsy()

【讨论】:

    【解决方案2】:

    您可以这样做,使用 isEnabled 代替 getAttribute 并使用 toBeFalsy 代替 toEqual 来验证复选框的状态。

    var cb = element(by.css('input'));
        cb .click().then(function(){
            cb .isEnabled().then(function(Checked){
                expect(Checked).toBeFalsy();
            })
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多