我有一個函數,它正確檢索元素的索引,哪個文本===「檢查」。它清楚地印在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