2015-09-25 86 views
2

我想从第二列值中选择表格中的特定元素(我删除了呈现的空白处),并且在找到该元素后,我想单击它(回报是真实的)。我试过这个,但它没有点击它,但只是找到了元素。TypeError:无法调用未定义的方法'点击'

该字段我想选择HTML代码如下:

<table ng-table="tableParams" id="Panel" class="tbl-option-list" template-pagination="directives/controls/Pager/Pager.html"> 
    <caption translate>Orders</caption> 
    <tr id="Panel"> 
     <!-- 1 --> 
     <th class="fixed-width-glyphicon"></th> 
     <!-- 2 --> 
     <th translate>Identifier</th> 
    </tr> 
     <tr ng-repeat="item in $data track by $index" ng-class="{'active-bg': order.$selected}" ng-click="changeSelection(order, getRowActions(order))"> 
     <!-- 1 --> 
     <td class="fixed-width-glyphicon"> 
      <div class="fixed-width-glyphicon"> 
       {{item.priority.toUpperCase()[0]}} 
      </div> 
     </td> 
     <!-- 2 --> 
     <td>{{item.identifierCode}}</td> 
    </tr> 
</table> 

从量角器的选择命令是:

var deferred = protractorData.p.promise.defer(); 
element.all(by.repeater('item in $data track by $index')).filter(function(row) { 
    row.getText().then(function(txt) { 
     txt = txt.replace(/\s/g, ''); 
     var found = txt.split('ID0001'); 
     return found.length > 1; 
    }); 
}).then(function(elem) { 
     deferred.fulfill(elem[0]); 
    }); 
    return deferred.promise; 
} 

我收到以下错误:

TypeError: Cannot call method 'click' of undefined.

+0

能否请您添加与您的代码的jsfiddle它会很容易调试;)在您尝试单击该元素似乎第一种观点不被显示。 – Radu

+0

@Radu,Protractor是一个node.js模块,它不会在JSFiddle中运行。 –

+1

你可以添加你的代码来点击元素吗?我想你是试图点击返回的承诺,而不是返回的元素。 –

回答

3

似乎元素没有被返回被点击。试试下面的例子来点击,看看它是否工作正确的过滤功能,而不是返回使用承诺的元素 -

element.all(by.repeater('item in $data track by $index')).filter(function(row) { 
    //return found element 
}).then(function(elem) { 
    elem[0].click(); //click it here 
}); 

或者在下面的方式返回元素,然后点击它在您的测试规范。以下是如何 -

var clickElement = element.all(by.repeater('item in $data track by $index')).filter(function(row) { 
    //return found element 
}).then(function(elem) { 
    return elem[0]; //return the element 
}); 
return protractor.promise.fulfilled(clickElement); 

希望它有帮助。

0

为什么你不只是返回元素?没有必要在这里promise.defered:

return element.all(by.repeater('item in $data track by $index')).filter(function(row) { 
    row.getText().then(function(txt) { 
    txt = txt.replace(/\s/g, ''); 
    var found = txt.split('ID0001'); 
    return found.length > 1; 
}); 
}).then(function(elem) { 
    return elem[0]; 
}); 

注意在开始添加的回报,这样,您是return elem[0];

0

的.filter函数返回一个承诺应该返回一个值。 在你的榜样,我相信它应该是(在第三行):

return row.getText().then(function(txt) { 
相关问题