无法使用量角器从表中找到元素

时间:2017-12-02 12:08:29

标签: angularjs protractor bluebird

无法使用量角器和蓝鸟承诺概念在表格中找到元素

HTML页面 - 使用angular JS:

<tr data-ng-repeat="tableRow in $ctrl.tableResults track by $index" id="case-list-table-row" class="ng-scope" style=""><!-- ngRepeat: tableTitle in $ctrl.tableTitles --><td data-ng-repeat="tableTitle in $ctrl.tableTitles" id="case-list-table-cell" class="ng-binding ng-scope">TFL7123631607</td><!-- end ngRepeat: tableTitle in $ctrl.tableTitles --><td data-ng-repeat="tableTitle in $ctrl.tableTitles" id="case-list-table-cell" class="ng-binding ng-scope">34</td><!-- end ngRepeat: tableTitle in $ctrl.tableTitles --><td data-ng-repeat="tableTitle in $ctrl.tableTitles" id="case-list-table-cell" class="ng-binding ng-scope">TFL</td><!-- end ngRepeat: tableTitle in $ctrl.tableTitles --><td data-ng-repeat="tableTitle in $ctrl.tableTitles" id="case-list-table-cell" class="ng-binding ng-scope">No Plea</td><!-- end ngRepeat: tableTitle in $ctrl.tableTitles -->

用于搜索和返回散文值的代码:

this.searchIndex = function (myurn) {
 return(()=> {
       var my_table = element(by.css("case-list-table tbody tr"));
       var td = my_table.element(by.css("td:first-child"));

       element.all(td.each(function (element, index) {
         element.getText().then(function (text) {
           console.log("outer" + text);
           console.log(index, text);
           if (text.matches(myurn)) {
             console.log("Inner" + text);
             return promise.props({ index:index});
                  }
         });
       });
     });
   };

我试图通过循环页面中的列并返回索引来查找ID。这样我就可以使用索引获得单独的元素,然后比较所有字段

1 个答案:

答案 0 :(得分:1)

据我所知,case-list-table不是标记名称,而是table元素的id值。你的意思不是:

table#case-list-table tbody tr

此外,您需要拥有所有承诺嵌套级别的return

this.searchIndex = function (myurn) {
    return(()=> {
        var my_table = element(by.css("table#case-list-table tbody tr"));
        var td = my_table.element(by.css("td:first-child"));

        return element.all(td.each(function (element, index) {
            return element.getText().then(function (text) {
                // ...

而且,each()实际上并不合适(我实际上怀疑这里的用法语法是否正确)。您正在过滤元素 - 使用filter()