量角器通过中继器单击元素

时间:2015-06-30 09:26:20

标签: testing protractor end-to-end

我试图通过转发器点击列表<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&#34;)行(&#34; 0&#34)&#34;

是否有人可以帮我找到点击<li>的方法?

1 个答案:

答案 0 :(得分:1)

相反,请尝试在first()上调用ElementArrayFinder

var rows = element.all(by.repeater("car in axCarSearch.found"));

rows.first().element(by.tagName("a")).click();
相关问题