我想通过第二列值从表中选择特定元素(我删除了呈现的空格),找到该元素后我想单击它(返回值为 true)。我已经尝试过这个,但它不会点击它,而只是找到该元素。
我要选择的字段的 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>
Protractor 的选择命令是:
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.
最佳答案
似乎该元素没有返回以供单击。尝试下面的示例来单击并查看它在过滤器函数中是否正常工作,而不是使用 Promise 返回元素 -
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);
希望有帮助。
关于javascript - 类型错误 : Cannot call method 'click' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32778709/