Protractor get element by model in repeater array

假如想象 提交于 2020-01-16 05:20:32

问题


For example, in HTML page:

<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>

Then, I want something like:

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

This returns an unable to find element. I am basing this on this question and answer: Protractor find element inside a repeater


回答1:


The value passed into by.model() should be as is on the page:

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

Note that activePost variable would refer to an element, hence even if it's value would be false (unchecked checkbox), the expect(activePost).toEqual(true); expectation would be met. You need to assert the checkbox's value instead using isSelected():

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


来源:https://stackoverflow.com/questions/28113641/protractor-get-element-by-model-in-repeater-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!