【问题标题】:How to find specific row in ng-table by text [protractor]如何通过文本在 ng-table 中查找特定行 [量角器]
【发布时间】:2015-12-19 07:55:34
【问题描述】:

我想通过第二列值从表中选择特定元素(我删除了呈现的空格),找到该元素后我想点击它。 (返回为真) 我试过这个,但它没有点击它,它只是找到元素。

我要选择的那个文件的 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>

量角器的选择命令是:

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;
    });
}).click();

Protractor 是一个基于 Selenium 的框架,用于 Angular js 自动化测试。即使是基于 Selenium 的解决方案也可以工作......

【问题讨论】:

  • 尝试将return放在row.getText().then(function(txt) { ...之前。
  • 谢谢,但不起作用....

标签: javascript angularjs selenium automated-tests protractor


【解决方案1】:

我猜你应该在尝试点击它们之前返回过滤后的元素。方法如下-

element.all(by.repeater('item in $data track by $index')).filter(function(row) {
    return row.getText().then(function(txt) {
        txt = txt.replace(/\s/g, '');
        var found = txt.split('ID0001');
        return found.length > 1;
    });
}).then(function(elem){
    elem[0].click();
});

希望这会有所帮助。

【讨论】:

  • 谢谢,但修改代码后收到如下错误:"errorMsg": "TypeError: Object has no method 'click'",
  • 我差点忘了,filter 函数返回一个元素数组查找器。所以应该使用 array[0] 点击第一个元素。更新了代码。您还可以查看.then() 函数中返回了多少元素。
  • P.S.你能告诉我你如何调试量角器测试吗?我的 IDE 是 Visual Studio Code。
  • 恐怕没有专门用于量角器的IDE。但是,您可以使用 IDE 的 javascript,它可以帮助您处理 JS 语法和一些您将在量角器脚本(如 WebStorm、Atom 或 Brackets)中使用的 javascript 函数。
猜你喜欢
  • 2017-12-19
  • 2018-09-06
  • 2015-11-08
  • 2019-08-14
  • 2011-06-07
  • 1970-01-01
  • 2016-04-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多