【发布时间】:2015-06-30 22:43:21
【问题描述】:
我正在尝试通过转发器单击列表 <li> 中的第一个元素
我的 HTML 看起来像:
<ul class="list-unstyled" ng-show="axCarSearch.found.length">
<!-- ngRepeat: car in axCarSearch.found --><li ng-repeat="car in axCarSearch.found" viewport-check="$index==axCarSearch.current" class="ng-scope">
<a class="clearfix current" ng-mousedown="axCarSearch.select(car)" ng-class="{current: $index==axCarSearch.current}">
<!-- ngRepeat: m in car.match track by $index --><!-- ngIf: $odd -->
<!-- ngIf: $even --><span ng-repeat-end="" ng-if="$even" ng-bind="m" class="ng-binding ng-scope">VW</span><!-- end ngIf: $even --><!-- end ngRepeat: m in car.match track by $index --><!-- ngIf: $odd --><strong ng-repeat-start="m in car.match track by $index" ng-if="$odd" class="text-primary ng-binding ng-scope" ng-bind="m">Passat</strong><!-- end ngIf: $odd -->
<!-- ngIf: $even --><!-- end ngRepeat: m in car.match track by $index --><!-- ngIf: $odd -->
<!-- ngIf: $even --><span ng-repeat-end="" ng-if="$even" ng-bind="m" class="ng-binding ng-scope">05/07-10/10 (3C)</span><!-- end ngIf: $even --><!-- end ngRepeat: m in car.match track by $index -->
<!-- ngIf: !car.match -->
<small class="pull-right text-muted ng-binding">Typ</small>
</a>
</li><!-- end ngRepeat: car in axCarSearch.found --><li ng-repeat="car in axCarSearch.found" viewport-check="$index==axCarSearch.current" class="ng-scope">
<a class="clearfix" ng-mousedown="axCarSearch.select(car)" ng-class="{current: $index==axCarSearch.current}">
<!-- ngRepeat: m in car.match track by $index --><!-- ngIf: $odd -->
<!-- ngIf: $even --><span ng-repeat-end="" ng-if="$even" ng-bind="m" class="ng-binding ng-scope">VW</span><!-- end ngIf: $even --><!-- end ngRepeat: m in car.match track by $index --><!-- ngIf: $odd --><strong ng-repeat-start="m in car.match track by $index" ng-if="$odd" class="text-primary ng-binding ng-scope" ng-bind="m">Passat</strong><!-- end ngIf: $odd -->
<!-- ngIf: $even --><!-- end ngRepeat: m in car.match track by $index --><!-- ngIf: $odd -->
<!-- ngIf: $even --><span ng-repeat-end="" ng-if="$even" ng-bind="m" class="ng-binding ng-scope">10/00-05/05 (3B3/3B6)</span><!-- end ngIf: $even --><!-- end ngRepeat: m in car.match track by $index -->
<!-- ngIf: !car.match -->
<small class="pull-right text-muted ng-binding">Typ</small>
</a>
</li><!-- end ngRepeat: car in axCarSearch.found --><li ng-repeat="car in axCarSearch.found" viewport-check="$index==axCarSearch.current" class="ng-scope">
<a class="clearfix" ng-mousedown="axCarSearch.select(car)" ng-class="{current: $index==axCarSearch.current}">
<!-- ngRepeat: m in car.match track by $index --><!-- ngIf: $odd -->
<!-- ngIf: $even --><span ng-repeat-end="" ng-if="$even" ng-bind="m" class="ng-binding ng-scope">VW</span><!-- end ngIf: $even --><!-- end ngRepeat: m in car.match track by $index --><!-- ngIf: $odd --><strong ng-repeat-start="m in car.match track by $index" ng-if="$odd" class="text-primary ng-binding ng-scope" ng-bind="m">Passat</strong><!-- end ngIf: $odd -->
<!-- ngIf: $even --><!-- end ngRepeat: m in car.match track by $index --><!-- ngIf: $odd -->
<!-- ngIf: $even --><span ng-repeat-end="" ng-if="$even" ng-bind="m" class="ng-binding ng-scope">10/96-09/00 (3B2/3B5)</span><!-- end ngIf: $even --><!-- end ngRepeat: m in car.match track by $index -->
<!-- ngIf: !car.match -->
<small class="pull-right text-muted ng-binding">Typ</small>
</a>
</li>
</ul>
您可以看到它的某种汽车列表,其中每个<li> 代表其中一辆。我基本上尝试点击一个特定的(从第一个开始)
我试着写这样的东西:
element(by.repeater('car in axCarSearch.found').row(0)).element(by.css('[ng-mousedown="axCarSearch.select(car)"]')).click();
很遗憾,我收到一个错误:
使用定位器找不到元素:by.repeater(car in axCarSearch.found").row("0")"
有没有人可以帮我找到点击<li>的方法?
【问题讨论】:
-
您可以尝试添加以下
element.all(by.repeater('car in axCarSearch.found')).count().then(function (count) { console.log(count); });,运行测试并查看控制台上的输出吗?谢谢。 -
嗨@alecxe它返回正确的选项数量,在这种情况下它是3
标签: testing protractor end-to-end