这是代码:
<div class="grid">
<button type="button" ng-click="addProductCategory()">Add</button>
<!-- ngRepeat: productCategory in productCategories --><div class="ng-scope" ng-repeat="productCategory in productCategories">
<div>
<p class="ng-binding">Category A</p>
</div>
<ul class="">
<li>
<a ng-click="updateProductCategory(productCategory, $event)" class="" href="#">Edit</a>
<a ng-click="deleteProductCategory(productCategory, $event)" class="" href="#">Delete</a>
</li>
</ul>
</div><!-- end ngRepeat: productCategory in productCategories --><div class="ng-scope" ng-repeat="productCategory in productCategories">
<div>
<p class="ng-binding">Category B</p>
</div>
<ul class="">
<li>
<a ng-click="updateProductCategory(productCategory, $event)" class="" href="#">Edit</a>
<a ng-click="deleteProductCategory(productCategory, $event)" class="" href="#">Delete</a>
</li>
</ul>
</div><!-- end ngRepeat: productCategory in productCategories --><div class="ng-scope" ng-repeat="productCategory in productCategories">
<div>
<p class="ng-binding">Category C</p>
</div>
<ul class="">
<li>
<a ng-click="updateProductCategory(productCategory, $event)" class="" href="#">Edit</a>
<a ng-click="deleteProductCategory(productCategory, $event)" class="" href="#">Delete</a>
</li>
</ul>
</div><!-- end ngRepeat: productCategory in productCategories --><div class="ng-scope" ng-repeat="productCategory in productCategories">
<div>
<p class="ng-binding">Category D</p>
</div>
<ul class="">
<li>
<a ng-click="updateProductCategory(productCategory, $event)" class="" href="#">Edit</a>
<a ng-click="deleteProductCategory(productCategory, $event)" class="" href="#">Delete</a>
</li>
</ul>
</div><!-- end ngRepeat: productCategory in productCategories --><div class="ng-scope" ng-repeat="productCategory in productCategories">
<div>
<p class="ng-binding">Category E</p>
</div>
<ul class="">
<li>
<a ng-click="updateProductCategory(productCategory, $event)" class="" href="#">Edit</a>
<a ng-click="deleteProductCategory(productCategory, $event)" class="" href="#">Delete</a>
</li>
</ul>
</div><!-- end ngRepeat: productCategory in productCategories --><div class="ng-scope" ng-repeat="productCategory in productCategories">
<div>
<p class="ng-binding">Category N</p>
</div>
<ul class="">
<li>
<a ng-click="updateProductCategory(productCategory, $event)" class="" href="#">Edit</a>
<a ng-click="deleteProductCategory(productCategory, $event)" class="" href="#">Delete</a>
</li>
</ul>
</div><!-- end ngRepeat: productCategory in productCategories -->
</div>
我可以根据其位置选择一个元素,但我尝试的是动态选择,但不是很有效,以下是我到目前为止所做的...
updateCatBtn: { get: function() { return element(by.cssContainingText('div', 'Devices')).element(by.xpath("(//a[contains(text(),'Edit')])")); }},
我也尝试了这个但是无法让它工作......
updateCatBtn: { get: function() { return element.all(by.binding('productCategory.name')).then(function(elements) { elements.filter(function(cName) { cName.getText().then(function (text) {return text == Category D;}); }).then(function (m) {m.element(by.linkText('Edit')); }); }); }},
有人可以帮我解决这个问题,谢谢。
答案 0 :(得分:0)
您可以按文字获取类别,然后点击following Edit
按钮:
//p[. = 'Category D']//following::a[. = 'Edit']