问题描述
这是我的代码-
formElements[0].findElements(by.repeater(repeater)).then(function(items){
console.log(i, '>>>>>>>>>.No of items in the list --- '+items.length);
(function(items){
for(var x1=0; x1<itemsToBeSelected.length; x1++){
console.log(i, '>>>>>>.Looking for item --- '+itemsToBeSelected[x1]);
skip = false;
(function(items, x1){
for(var x2=0; x2<items.length; x2++){
(function(items, x2){
items[x2].getText().then(function(itemName){
console.log(i, '>>>>..Verifying '+itemsToBeSelected[x1]+' with '+itemName);
if(itemName == itemsToBeSelected[x1]){
console.log(i, '>>>>>.Selecting the item --- '+itemName);
items[x2].findElement(by.css('.regular-checkbox')).click();
}
});
}(items, x2));
}
}(items, x1));
}
}(items));
});
当条件itemName == itemsToBeSelected [x1]满足时,我想突破内部for循环.尝试使用标志,返回语句,但无法从循环中退出.
I want to break out of inner for loop when the condition itemName == itemsToBeSelected[x1] is satisfied. Tried using flag, return statements, but unable to break out from the loop.
请在代码中提出更正建议.
Please suggest corrections in the code.
推荐答案
ptor.element.all(by.repeater(repeater)).then(function(products){
console.log(i, '>>>>>>>>>.Products length --- '+products.length);
async.each(products, verifyName, function(err){
console.log('>>>>>>>>>>>err value --- '+err);
expect(err).toBe(true);
if(err){
console.log(i, '>>>>>>>>.Element is present');
}else{
console.log(i, '>>>>>>>>.Element is not present');
}
});
function verifyName(product, callback){
console.log(i, '>>>>>>>>.Inside function verifyName');
product.getText().then(function(name){
console.log('>>>>>>>>>>Looking for product --- '+name);
if(name==entityName){
console.log(i, '>>>>>>>>Verified the name - '+name);
callback(true);
}
});
}
});
我们也可以借助async.each模块获得相同的结果.例如我已经发布了一个代码,试图在其中找到一个值.
We can achieve the same results with the help of async.each module as well. For e.g. I've posted a code in which i'm trying to find a single value.
因此,关于我的问题,我们可以在设置callback(true)之前单击或对元素执行任何操作.例如说在这里我们可以做-product.click();
So in relation to my question, we can click or perform any action on the element before setting callback(true). Say for e.g. here we could do - product.click();
这篇关于如何突破量角器的for循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!