如何从Angularjs应用程序中的表中获取特定的单元格数据

时间:2016-01-29 15:52:42

标签: javascript node.js protractor

我想从此表中获取数据“Crab”:

Sushi Roll   FishType   Taste Level
Cali Roll    Crab            2
Philly       Tuna            4
Rainbow      Variety         6
Tiger        Eel             7

下面是检索最后一行数据但我需要从第2行第2列(Crab)获取数据的代码

var rows = element.all(by.repeater('roll in sushi | orderBy:sortType:sortReverse | filter:searchFish'));
//var rows = element.all(by.repeater('alert in alerts'));
var row = rows.last();
var rowElems = row.all(element(by.tagName('td')));
console.log(row.get(0).getText());

下面是外部html

<span ng-show="sortType == 'fish' &amp;&amp; !sortReverse" class="fa fa-caret-down ng-hide"></span>
<tr class="ng-scope" ng-repeat="roll in sushi | orderBy:sortType:sortReverse | filter:searchFish">
        <td class="ng-binding">Tiger</td>
        <td class="ng-binding">Eel</td>
        <td class="ng-binding">7</td>
      </tr>

1 个答案:

答案 0 :(得分:1)

使用.get(index) index从0开始:

var rows = element.all(by.repeater('roll in sushi | orderBy:sortType:sortReverse | filter:searchFish'));
var row = rows.get(1);
var rowElems = row.all(element(by.tagName('td')));

console.log(rowElems.get(1).getText());