How to find and click a table element by text using Protractor?

江枫思渺然 提交于 2019-12-21 20:01:51

问题


<tr id="item" ng-repeat="item in itemList>
   <td id="code" ng-repeat="column in columns">Some Text</td>
</tr>

I've seen some other similar questions but I couldn't solve it yet. Thats what I've tried so far:

element.all(by.repeater('column in columns')).findElement(by.id('code')).getText('Some Text').click();

EDIT:

<tr ng-repeat="item in items>
<td>{{item.name}}</td>
<td>{{item.description}}</td>
</tr>

Which results in:

<tr>
<td>Some Name</td>
<td>Some Text</td>
</tr>
<tr>
<td>More Name</td>
<td>More Text</td>
</tr>

etc etc


回答1:


You need to filter() the desired element:

var columns = element.all(by.repeater('column in columns'));
columns.filter(function (elm) {
    return elm.getText().then(function (text) {
        return text == 'Some Text';
    });
}).first().click();


来源:https://stackoverflow.com/questions/30594974/how-to-find-and-click-a-table-element-by-text-using-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!