量角器在中继器阵列模式得到元素 [英] Protractor get element by model in repeater array

查看:276
本文介绍了量角器在中继器阵列模式得到元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在HTML页面:

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

这将返回一个无法找到的元素。我对这个问题的回答与此基础:
<一href=\"http://stackoverflow.com/questions/22757340/protractor-find-element-inside-a-repeater\">Protractor找到一个中继内元素

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

推荐答案

传入 by.model()的值应尽可能在页面上:

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

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

注意 activePost 变量会提到一个元素,因此即使它的价值将是(选中复选框),在预期(activePost).toEqual(真); 预期将得到满足。您需要断言复选框的值,而不是使用 isSelected()

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

这篇关于量角器在中继器阵列模式得到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆