2
我正在開發我的angular e2e測試項目。我將下面的html作爲我的ng-repeat的一部分生成,並且不包含任何id,我想選擇與標題Topic - xyz一起使用的第二個元素,然後單擊它是兄弟的子元素的按鈕。我怎樣才能做到這一點。從元素數組中選擇第n個元素jquery
<div class="row ng-scope" ng-repeat="post in posts">
<div class="col-md-7">
<h4 class="ng-binding">Topic - ABC</h4>
<div class="text-right">
<button class="btn btn-none btn-sm" ng-click="posts.newPost()">
Create Post
</button>
</div>
</div>
</div>
<div class="row ng-scope" ng-repeat="post in posts">
<div class="col-md-7">
<h4 class="ng-binding">Topic - XYZ</h4>
<div class="text-right">
<button class="btn btn-none btn-sm" ng-click="posts.newPost()">
Create Post
</button>
</div>
</div>
</div>
<div class="row ng-scope" ng-repeat="post in posts">
<div class="col-md-7">
<h4 class="ng-binding">Topic - EFG</h4>
<div class="text-right">
<button class="btn btn-none btn-sm" ng-click="posts.newPost()">
Create Post
</button>
</div>
</div>
</div>
這是我一直在努力,到目前爲止,這是不工作
var button = $$(by.repeater('post in posts')).get(1).$(by.css('[ng-click="posts.newPost()"]'))
button.click(); // click is not showing up
謝謝alecxe,我已經使用了最後的解決方案,因爲我已經得到了直到var post = element.all(by.repeater('post in posts'))。get(1);你的解決方案就像魅力一樣 –