我有一个函数,它正确检索元素的索引,哪个文本===“检查”。它清楚地印在console.log上:如何从量角器的承诺链中检索数据?
function getIndex() {
return element.all(by.css(".palette__item.ng-scope>span")).then(function (colorList) {
colorList.forEach(function (elem, index) {
elem.getText().then(function (text) {
if (text == "check") {
console.log(index);
return index;
}
});
});
});
}
然后,我尝试了很多不同的方法,如何从中检索数据,但没有成功。塔最后一种方法是这样的:
var res = null;
webDriver.promise.fullyResolved(getIndex()).then(function (index) {
res = index;
});
console.log(res);
所以,在这里我已经尝试的功能,这guaratees任何承诺的决心里面的init资源的价值,但它不工作,并返回null。
我认为,我在getIndex()函数中有错误,也许,我已将return opertor放置在错误的地方,但我需要帮助。我完全不知道如何使它工作。请帮助。
非常有趣,但我得到'undefined'valuse。我很抱歉,如果我的问题很蠢,我刚开始使用JS进行测试。 – SanchelliosProg
@SanchelliosProg啊,nono,我很笨,忘了'return'。请再试一次。 – alecxe
你是我的SUPERHERO !!!!!!!!你救了我的生命))))非常感谢你! – SanchelliosProg