如何通过文本 [protractor] 在 ng-table 中查找特定行

How to find specific row in ng-table by text [protractor]

我想 select 来自 table 第二列值的特定元素(我删除了呈现的空格),找到该元素后我想点击它。 (return 是真的) 我已经试过了,但它没有点击它,它只是找到了元素。

我想要 select 的那个文件的 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命令是:

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 筛选元素,然后再尝试点击它们。方法如下 -

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

希望对您有所帮助。