trees_are_great
trees_are_great

Reputation: 3911

Protractor get element by model in repeater array

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

Upvotes: 1

Views: 2591

Answers (1)

alecxe
alecxe

Reputation: 474271

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();

Upvotes: 3

Related Questions