如何在列表框中找到用于选择记录的元素

时间:2015-12-09 11:01:05

标签: angularjs automation protractor

我想从列表框中选择记录并保存页面。保存后,选定的记录将填充在列表的顶部。未选中的记录将显示在所选记录列表下方。

  1. 如何识别列表框中的非选定记录以选择下次更新中的记录。
  2. 如何识别列表中的选定记录数据以存储在变量中。
  3. 以下是非选择记录的元素

    <li ng-class="{'list-group-item-info': agent.$selected}" ng-repeat="agent in newAgents" style="padding: 5px 15px;" class="list-group-item ng-binding ng-scope" ng-click="toggleSelection(0, 'newAgent')"><span ng-show="agent.$selected" class="label label-success ng-hide"><small><span class="glyphicon glyphicon-ok"></span></small></span> Anto</li>
    
    <li ng-class="{'list-group-item-info': agent.$selected}" ng-repeat="agent in newAgents" style="padding: 5px 15px;" class="list-group-item ng-binding ng-scope" ng-click="toggleSelection(1, 'newAgent')"><span ng-show="agent.$selected" class="label label-success ng-hide"><small><span class="glyphicon glyphicon-ok"></span></small></span> LokeshMahalingam</li>
    

    这是选定记录的HTML元素

    <li ng-class="{'list-group-item-danger': agent.$selected}" ng-repeat="agent in agents" style="padding: 5px 15px;" class="list-group-item-success ng-binding ng-scope" ng-click="toggleSelection(0, 'agent')"><span ng-show="agent.$selected" class="label label-danger ng-hide"><small><span class="glyphicon glyphicon-remove"></span></small></span>Christopher</li>
    

    代码就是我现在正在使用的。 (此代码仅选择第一条记录是否已选中)

    this.SkillAgent = element(by.css('li[ng-repeat="agent in newAgents"]'));
    

    我也尝试了以下代码,但没有工作

    this.SkillAgent = element(by.css('li[ng-click="toggleSelection(0, newAgent)"]'));
    

2 个答案:

答案 0 :(得分:2)

首先,有一个相关的by.repeater()定位器:

this.SkillAgent = element.all(by.repeater("agent in newAgents"));

要识别所选元素,我们可以使用filter()函数与evaluate()来评估agent.$selected的值:

this.selectedAgents = this.SkillAgent.filter(function (agent) {
    return agent.evaluate("agent.$selected").then(function (isSelected) {
        return isSelected;
    });
}):

或者,检查是否存在list-group-item-danger类:

this.selectedAgents = $$("li.list-group-item-danger");

答案 1 :(得分:1)

我可以通过get函数在列表框中选择值。 1,2 ...是列表框中的数据行。

this.SkillAgent1 = element.all(by.repeater("agent in newAgents")).get(1);
this.SkillAgent2 = element.all(by.repeater("agent in newAgents")).get(2);