私は次のコードスニペットを持っています。私のコードを随時ループ/約束を解除して関数から戻る
this.clickButtonText = function (buttonText, attempts, defer) {
var me = this;
if (attempts == null) {
attempts = 3;
}
if (defer == null) {
defer = protractor.promise.defer();
}
browser.driver.findElements(by.tagName('button')).then(function (buttons) {
buttons.forEach(function (button) {
button.getText().then(
function (text) {
console.log('button_loop:' + text);
if (text == buttonText) {
defer.fulfill(button.click());
console.log('RESOLVED!');
return defer.promise;
}
},
function (err) {
console.log("ERROR::" + err);
if (attempts > 0) {
return me.clickButtonText(buttonText, attempts - 1, defer);
} else {
throw err;
}
}
);
});
});
return defer.promise;
};
は「:古い要素参照:ERROR :: StaleElementReferenceErrorを要素は、ページの文書に添付されていない」達するラインので、私はもう一度試してみて「の試みと私の関数を起動する必要があります - 1 "パラメータ。それは期待される行動です。 しかし、一度それがに達したら "解決済み!" (「!RESOLVED」):質問がある
button_loop:wrong_label_1
button_loop:CORRECT_LABEL
RESOLVED!
button_loop:wrong_label_2
button_loop:wrong_label_3
button_loop:wrong_label_4
:それはので、私はこのようななめらかを参照してください反復し続けるラインループ/約束を破るとにconsole.log後に関数から返す方法。行?
あなたは '.done'コールバックを使ってみましたか? –
いいえ、私の共有遅延が解決されているかどうかを確認しているようです。よりエレガントな答えを待つだろうし、私自身のものを提供しない場合 –