我无法获取下面提到的表格的单元格数。我想只在表格中获取计数。请帮助我实现这一点 - 我希望得到的数量 -
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$0.90</td>
&#13;
请告诉我如何实现这一目标。谢谢!
<div class="show-for-large-up">
<table>
<thead>
<tr>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<th class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0" ng-bind-html="receiptTemplate.paymentFee" width="300">Payment Fee</th>
<!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
</tr>
</thead>
<tbody>
<!-- ngRepeat: lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index -->
<tr class="ng-scope" ng-repeat="lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index">
<td class="ng-binding">$45.00</td>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$0.90</td>
<!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
</tr>
<!-- end ngRepeat: lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index -->
<tr class="ng-scope" ng-repeat="lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index">
<td class="ng-binding">Jul 21, 2017</td>
<td class="ng-binding">$0.00</td>
<!-- ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$1.68</td>
<!-- end ngIf: paymentDetails.responseObject[0].fee_amount > 0 -->
</tr>
</tbody>
</table>
</div>
&#13;
我尝试了什么 - 但我得到的数字为3.实际上,计数应为1
var paymentTable = $$('.show-for-large-up tr');
var row = paymentTable.$$('[ng-repeat="lineItem in paymentDetails.responseObject[0].schedules[0].schedule_line_items track by $index"]');
var cell = row.$$('[ng-if="paymentDetails.responseObject[0].fee_amount > 0"]');
var cellCount = cell.filter(function(elm) {
return elm.count();
expect(elm.count()).toBe(1);
});
&#13;
答案 0 :(得分:1)
过滤器不起作用,因为过滤器将获得第一个匹配元素且不计数,另请参阅docs
您可以使用each来实现此目的。您迭代每个匹配的元素,然后执行您需要的操作。您的代码看起来像这样
var count = 0;
// Get all the td's
$$('[ng-if="paymentDetails.responseObject[0].fee_amount > 0"]')
// Walk through all the found td's
.each((element) => {
// Get the text of the td
return element.getText()
.then((text) => {
// Add a + 1 if the text matches
if (text === '$0.90') {
count + 1;
}
});
});
// Do the assertion
expect(count).toBe(1);