UI量角器查找&单击“基于文本搜索选择框”

时间:2015-03-31 15:34:31

标签: angularjs protractor chai

我正在尝试找到一种方法来搜索其中包含名称X的行,然后使用UI Protractor单击该行中的复选框。

到目前为止我一直很失败。

如果您看到以下内容,我想搜索 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>

1 个答案:

答案 0 :(得分:3)

尝试过滤功能,我添加了一些注释以使其可读:

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