Javascript 使用量角器从阵列测试中获取数据
我用对象创建了一个数组,它有不同的值,我需要测试一个特定数组的内容,所以我使用了Javascript 使用量角器从阵列测试中获取数据,javascript,angularjs,ionic-framework,ionic,protractor,Javascript,Angularjs,Ionic Framework,Ionic,Protractor,我用对象创建了一个数组,它有不同的值,我需要测试一个特定数组的内容,所以我使用了 var child = element.all(by.css('.col.col-top.col-67')),element.all(by.css('.ng-binding')); expect(child.get(1)).toEqual('HAL 9000'); 这会在我的终端中发送错误消息“致命错误:调用\u和\u重试\u上次分配失败-进程内存不足 中止陷阱:6“ 实际上,我需要检查html页面中是
var child = element.all(by.css('.col.col-top.col-67')),element.all(by.css('.ng-binding'));
expect(child.get(1)).toEqual('HAL 9000');
这会在我的终端中发送错误消息“致命错误:调用\u和\u重试\u上次分配失败-进程内存不足
中止陷阱:6“
实际上,我需要检查html页面中是否显示了HAL9000
<a class="item-content" ng-href="#/lead/details/1/" target="_self" href="#/lead/details/1/">
<div class="row" style="height: 35px; width: 100%; margin-left:-10px; margin-top: -10px; margin-right: 0px; padding: 0px">
<div class="col col-top col-67">
<h2 class="ng-binding">HAL 9000</h2>
<br>
<h4 style="font-weight: normal; margin-top: -15px" class="ng-binding">Jupiter Feb 10, 2025 </h4>
</div>
<div class="col col-center col-10 col-offset-25" style="margin-right: -10px">
<a href="tel:9876543210" ng-click="$event.stopPropagation()">
<i class="icon ion-ios-telephone-outline" style="font-size: 36px"></i>
</a>
</div>
<div class="col col-center col-20" style="margin-left: 15px">
<a href="mailto:hai@spaceodyssey.com?Subject=Hi;" ng-click="$event.stopPropagation()">
<i class="icon ion-ios-email-outline" style="font-size: 36px;"></i>
</a>
</div>
</div>
</a>
元素.all()
不能附加到元素.all()
的实例。此外,您使用的是,
而不是
尝试将.ng绑定拆分为.ng绑定
,这样无需使用数组即可获得绑定。如果必须获取.col.col-top.col-67下的所有元素,请使用.each()
函数获取该类中的每个div,然后使用每个div获取具有.ng绑定的所有元素。这是怎么做的-
element.all(by.css('.col.col-top.col-67')).each(function(eachDiv){ //get each div with the specified class
var child = eachDiv.$$('.ng-binding'); //get all the elements with ng-binding under each div
expect(child.get(1)).toEqual('HAL 9000'); //add your expectations
});
注意:当您使用each()
时,它使用该元素定位器在所有元素中循环,就像for
循环一样。假设有许多元素具有类.col.col-top.col-67
,并且有许多元素在其下具有类.ng binding
如果只有一个元素,那么您不必在上述代码中使用element.all()
。希望它能帮助元素。all()
不能附加到元素的实例。all()
。此外,您使用的是,
而不是
尝试将.ng绑定拆分为.ng绑定
,这样无需使用数组即可获得绑定。如果必须获取.col.col-top.col-67下的所有元素,请使用.each()
函数获取该类中的每个div,然后使用每个div获取具有.ng绑定的所有元素。这是怎么做的-
element.all(by.css('.col.col-top.col-67')).each(function(eachDiv){ //get each div with the specified class
var child = eachDiv.$$('.ng-binding'); //get all the elements with ng-binding under each div
expect(child.get(1)).toEqual('HAL 9000'); //add your expectations
});
注意:当您使用each()
时,它使用该元素定位器在所有元素中循环,就像for
循环一样。假设有许多元素具有类.col.col-top.col-67
,并且有许多元素在其下具有类.ng binding
如果只有一个元素,那么您不必在上述代码中使用element.all()
。希望对您有所帮助谢谢您的帮助,我只是稍微修改了Girish Sortur提供的上述代码
var lItems = element.all(by.css('.col.col-top.col-67'));
var child = lItems.get(1).$$('.ng-binding'); //get all the elements with ng-binding under each div
expect(child.get(0).getText()).toEqual('HAL 9000'); //add your expectations
谢谢你的帮助,我只是稍微修改了上面Girish Sortur给出的代码
var lItems = element.all(by.css('.col.col-top.col-67'));
var child = lItems.get(1).$$('.ng-binding'); //get all the elements with ng-binding under each div
expect(child.get(0).getText()).toEqual('HAL 9000'); //add your expectations
谢谢,但我收到了err msg“TypeError:eachDiv.element.all不是函数”@YokeshVaradhan更新的答案。如果你还有任何错误,请告诉我。谢谢你,但我收到错误消息“TypeError:eachDiv.element.all不是函数”@YokeshVaradhan更新的答案。如果你还有任何错误,请告诉我。谢谢