【问题标题】:Protractor get element by model in repeater array量角器在转发器数组中按模型获取元素
【发布时间】:2015-01-23 15:51:15
【问题描述】:

例如在 HTML 页面中:

<tr ng-repeat="post in posts">
    <td ng-click="activePost(post)" class="title">{{post.title}}</td>
    <td><button class="btn btn-danger" ng-click="delete(post)">Delete</button></td>
  <td><input type="checkbox" ng-model="post.active" 
        id="{{post.id}}" /></td>
 </tr>

然后,我想要类似的东西:

element.all(by.repeater('post in posts')).then(function(posts) {
   var activePost = posts[0].element(by.model('active'));
   expect(activePost).toEqual(true);
});

这会返回一个无法找到的元素。我基于这个问题和答案: Protractor find element inside a repeater

【问题讨论】:

    标签: angularjs testing protractor angularjs-e2e end-to-end


    【解决方案1】:

    传递给by.model()的值应该与页面上的一样:

    var activePost = posts[0].element(by.model('post.active'));
    

    请注意,activePost 变量将引用一个元素,因此即使它的值是 false(未选中复选框),也会满足 expect(activePost).toEqual(true); 的期望。你需要assert the checkbox's value instead using isSelected():

    expect(activePost.isSelected()).toBeTruthy();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多