![](/img/trans.png)
[英]jQuery click event error: "TypeError: cannot call method 'toString' on undefined
[英]TypeError: Cannot call method 'click' of undefined
我想通過第二列值從表中選擇特定元素(我刪除了呈現的空白),找到該元素后,我想單擊它(返回值為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>
量角器的select命令為:
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:無法調用未定義的方法“ click”。
似乎該元素沒有返回被單擊。 請嘗試下面的示例,單擊以查看它是否在過濾器函數中正確運行,而不是使用promises返回元素-
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);
希望能幫助到你。
您為什么不只返回元素? 不需要諾言。這里延遲:
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];
的承諾return elem[0];
.filter函數應返回一個值。 在您的示例中,我認為應該是(第三行):
return row.getText().then(function(txt) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.