0

我无法获取下表中单元格的计数。我想只在表格主体中获取计数。请帮助我实现这一点-我希望得到计数-

<td class="ng-binding ng-scope" ng-if="paymentDetails.responseObject[0].fee_amount > 0">$0.90</td>

请让我知道如何实现这一目标。谢谢!!

<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>

我试过的 - 但我得到的计数是 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);
});

见下图 希望获取列付款费用的行数

4

1 回答 1

1

过滤器将不起作用,因为过滤器将获取第一个匹配元素并且不计算在内,另请参阅文档

您可以使用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);

于 2017-07-23T11:59:02.193 回答