gpt4 book ai didi

javascript - 无法将 For Loop 与 Promises 一起使用

转载 作者:行者123 更新时间:2023-11-29 21:41:43 24 4
gpt4 key购买 nike

我需要做的是我必须单击一些图像,然后文本在另一个元素中发生变化。我正在使用带有 promises 的 For 循环,因此我能够成功地逐一单击图像,但没有显示文本。它显示最后一个文本 5 次。请帮忙

element.all(by.xpath(".//*[@ng-repeat='num in facesGrid[$index]']")).then(function(faces){



for(var i=0;i<faces.length;i++)
{
element(by.model('currentTestimonialIndex')).getText().then(function(Index){
console.log(Index);
});
faces[i].click();



}

});

最佳答案

使用each()而不是 for 循环并通过 exact repeater 找到“面孔” :

element.all(by.exactRepeater("num in facesGrid")).each(function (face) {
element(by.model('currentTestimonialIndex')).getText().then(function (text) {
console.log(text);
});

face.click();
});

请注意,这仍然是一个猜测,因为您没有向我们提供您正在处理的页面的来源 - 什么是 currentTestimonialIndex 是个谜。

关于javascript - 无法将 For Loop 与 Promises 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32588403/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com