UI 量角器查找并单击 Select 基于文本搜索的框
UI Protractor Find & Click Select Box Based On Text Search
我正在尝试找到一种方法来搜索其中包含名称 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 && isAdd">No available proxies.</p>
<p class="lead ng-hide" ng-show="model.selectedServers.length === 0 && !isAdd">There are no proxies to remove.</p>
</div>
</div>
尝试过滤功能,我添加了一些注释以使其可读:
//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();
});
我正在尝试找到一种方法来搜索其中包含名称 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 && isAdd">No available proxies.</p>
<p class="lead ng-hide" ng-show="model.selectedServers.length === 0 && !isAdd">There are no proxies to remove.</p>
</div>
</div>
尝试过滤功能,我添加了一些注释以使其可读:
//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();
});