我正在尝试为我的HTML
测试点击事件html
<div class="testGroup">
<div ng-repeat="test in tests">
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
</div>
</div>
<div class="testGroup">
<div ng-repeat="test in tests">
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
</div>
</div>
<div class="testGroup">
<div ng-repeat="test in tests">
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
<a ng-click="clickMe(test.id)">{{test.name}}</a>
</div>
</div>
三个div是相同的但我想选择第一个testGroup类并单击第一个标签。我还想在第二个testGroup类上单击第一个标记。
在我的spec.js
中element.all(by.css('.testGroup')).get(0).then(function(elem) {
element(by.repeater('test in tests').row(0)).click();
});
我得到undefined不是函数错误。我认为这是因为get(0)不是承诺。如何触发第一个testGroup div中的第一个标签和第二个testGroup div中的第一个标签?谢谢你的帮助。
答案 0 :(得分:2)
这样的工作会好吗?
>>> Golfer #1 trying to fill bucket with 5 balls.
<<< Golfer #1 filled bucket with 5 balls, size = 15
>>> Golfer #5 trying to fill bucket with 5 balls.
<<< Golfer #5 filled bucket with 5 balls, size = 10
>>> Golfer #2 trying to fill bucket with 5 balls.
<<< Golfer #2 filled bucket with 5 balls, size = 5
>>> Golfer #3 trying to fill bucket with 5 balls.
<<< Golfer #3 filled bucket with 5 balls, size = 0
>>> Golfer #4 trying to fill bucket with 5 balls.
Golfer #1 hit ball #1 onto field.
Golfer #3 hit ball #16 onto field.
Golfer #5 hit ball #6 onto field.
Golfer #1 hit ball #2 onto field.
Golfer #2 hit ball #11 onto field.
*********** Bollie collecting balls ************
*********** Bollie adding 5 balls to stash ************
*********** Bollie added 5 balls to stash ************
Current stash size: 5
Golfer #1 hit ball #3 onto field.
Golfer #2 hit ball #12 onto field.
Golfer #3 hit ball #17 onto field.
Golfer #5 hit ball #7 onto field.
Golfer #1 hit ball #4 onto field.
Golfer #2 hit ball #13 onto field.
Golfer #1 hit ball #5 onto field.
>>> Golfer #1 trying to fill bucket with 5 balls.
<<< Golfer #1 filled bucket with 5 balls, size = 0
Golfer #2 hit ball #14 onto field.
Golfer #5 hit ball #8 onto field.
*********** Bollie collecting balls ************
*********** Bollie adding 9 balls to stash ************
*********** Bollie added 9 balls to stash ************
Current stash size: 9
Golfer #5 hit ball #9 onto field.
Golfer #3 hit ball #18 onto field.
Golfer #1 hit ball #1 onto field.
Golfer #1 hit ball #16 onto field.
Golfer #2 hit ball #15 onto field.
>>> Golfer #2 trying to fill bucket with 5 balls.
<<< Golfer #2 filled bucket with 5 balls, size = 4
Golfer #1 hit ball #6 onto field.
BUILD STOPPED (total time: 7 seconds)
$$是css。
的element.all的缩写答案 1 :(得分:1)
then()
上不再ElementFinder
(since 2.0)。
链element
和element.all()
,使用by.repeater()
和column()
:
var testGroups = element.all('.testGroup');
var testGroupOneTag = testGroups.first().element(by.repeater("test in tests").column("test.name"));
var testGroupTwoTag = testGroups.get(1).element(by.repeater("test in tests").column("test.name"));
testGroupOneTag.click();
testGroupTwoTag.click();