Diana
Diana

Reputation: 105

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

I want to select specific element from a table by the second column value (I removed the whitespaces that where rendered), and after that element is found I want to click on it. (the return in true) I've tried this, but it doesn't click on it, it just finds the element.

The html code for that filed I want to select is the following:

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

The select command from protractor is:

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 is a framework based on Selenium made for angular js automated testing. Even a solution based on Selenium may work...

Upvotes: 3

Views: 4518

Answers (1)

giri-sh
giri-sh

Reputation: 6962

You should return the filtered elements before trying to click on them i guess. Here's how -

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

Hope this helps.

Upvotes: 3

Related Questions