UI量角器查找和点击选择框基于文本的搜索(UI Protractor Find & Click Se

2019-10-22 10:41发布

我试图找到一种方法来搜索中有名为X的行,然后使用UI量角器该行中点击复选框。

我一直很成功为止。

如果你看到下面,我想搜索testproxy然后单击与之相关联的复选框。

<div id="general_section">
            <p> The following proxies are available to add to a cluster.</p>
            <div class="table-responsive">
                <table id="proxies_table" class="table table-striped table-bordered">
                    <thead>
                    <tr>
                        <th><input type="checkbox" ng-model="selectAll" ng-click="selectAllServers(selectAll)" class="ng-pristine ng-untouched ng-valid"></th>
                        <th res-key="settings.emailProxy.proxy">Proxy</th>
                    </tr>
                    </thead>
                    <tbody>
                    <!-- ngRepeat: server in model.selectedServers | orderBy:'hostname' --><tr ng-repeat="server in model.selectedServers | orderBy:'hostname'">
                        <td>
                            <input type="checkbox" ng-model="server.selected" class="ng-pristine ng-untouched ng-valid">
                        </td>
                        <td>
                            testproxy
                        </td>
                    </tr><!-- end ngRepeat: server in model.selectedServers | orderBy:'hostname' --><tr ng-repeat="server in model.selectedServers | orderBy:'hostname'">
                        <td>
                            <input type="checkbox" ng-model="server.selected" class="ng-pristine ng-valid ng-touched">
                        </td>
                        <td>
                            testproxy_1
                        </td>
                    </tr><!-- end ngRepeat: server in model.selectedServers | orderBy:'hostname' -->
                    </tbody>
                </table>
                <p class="lead ng-hide" ng-show="model.selectedServers.length === 0 &amp;&amp; isAdd">No available proxies.</p>
                <p class="lead ng-hide" ng-show="model.selectedServers.length === 0 &amp;&amp; !isAdd">There are no proxies to remove.</p>
            </div>
        </div>

Answer 1:

尝试过滤功能,我添加了一些意见,使之成为可读。

//filter through each row using the ng-repeat as locator
$$('[ng-repeat="server in model.selectedServers | orderBy:\'hostname\'"]').filter(function(foo){
    //check for the text in the td with index 1, aka the second one
    return foo.$$('td').get(1).getText().then(function(bar){
        //return the row which has your value (textproxy)
        return bar === "testproxy";
    });
//Here you can use the elements in the row with your value
//So you'd want to click the checkbox
}).then(function(values){
    values[0].$('[type="checkbox"]').click();
});


文章来源: UI Protractor Find & Click Select Box Based On Text Search