使用量角器中的行中的文本获取行号 [英] Get row number using text in the row in Protractor

查看:83
本文介绍了使用量角器中的行中的文本获取行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格结构如下

<table class="table">
  <thead>
    <tr>
      <th class="checkbox-column"></th>
      <th class="main-column main-column--checkbox">Name</th>
    </tr>
  </thead>
  <tbody ng-repeat="(a, b) in tests" class="ng-scope" style="">
    <tr class="panel__sub-header">
      <td>
        <input name="item-checkbox" ng-click="toggleSelectAll(a)" type="checkbox">
      </td>
      <td colspan="4">
        <h4 class="ng-binding">ROW2</h4>
      </td>
    </tr>
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style="">
      <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td>
      <td class="main-column">
        <a ng-href="#" class="ng-binding" href="#">test.name</a>
      </td>
    </tr>
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style="">
      <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td>
      <td class="main-column">
        <a ng-href="#" class="ng-binding" href="#">test.data</a>
      </td>
    </tr>
  </tbody>
  <tbody ng-repeat="(a, b) in tests" class="ng-scope" style="">
    <tr class="panel__sub-header">
      <td>
        <input name="item-checkbox" ng-click="toggleSelectAll(a)" type="checkbox">
      </td>
      <td colspan="4">
        <h4 class="ng-binding">ROW1</h4>
      </td>
    </tr>
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style="">
      <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td>
      <td class="main-column">
        <a ng-href="#" class="ng-binding" href="#">test.name</a>
      </td>
    </tr>
    <tr ng-repeat="test in testData" ng-class-odd="'odd'" ng-class-even="'even'" class="ng-scope odd" style="">
      <td class="checkbox-column"><input name="item-checkbox" ng-click="checkFunction()" type="checkbox"></td>
      <td class="main-column">
          <a ng-href="#" class="ng-binding" href="#">test.data</a>
      </td>
    </tr>
  </tbody>
</table>

我需要使用以下
获取表格单元格element(by.repeater('(a,b)in tests')。row(0))。element(by.css('[xxx]'))。当前正在使用硬编码的行号来实现此目的,但是由于动态UI更改,它始终无法正常工作

I need to get the table cell by using the below element(by.repeater('(a, b) in tests').row(0)).element(by.css('[xxx]')). Currently am using the hard coded row number to achieve this but its not working all the time due to the dynamic UI changes

是否可以使用by获取行号在量角器中传递文本

Is that possible to get the row number using the by passing the text in protractor

例如:
如果我传递文本 ROW2 ,则应返回行号,在测试中使用中继器(a,b)为0,那么我可以动态使用行号

Ex: If I pass the text ROW2 then it should return the row number as 0 using the repeater (a, b) in tests then I can able to use the row number dynamically

推荐答案

您可以使用 filter()方法来获取包含预期结果的特定行,而不是通过获取行号来实现

Instead of doing it by getting row number, you can use filter() method to get the particular row that contains the expected text.

var columnElement = element.all(by.repeater('(a, b) in tests')).filter(function(rowElement){
   return rowElement.element(by.css("td h4")).getText().then(function(text){
    return text.trim() == "ROW2"
  });
}).first().element(by.css("somecss"));

这篇关于使用量角器中的行中的文本获取行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆