In selenium JavaScript, I have to refresh the page until element is disappeared. Since it uses promises, if I use for loop it will create many promise even if the condition is satisfied, later it will be resolved. Also I have to provide driver.sleep(5000) mandatory due to some reason.
$browser.get("https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html").
then( function()
{
var p=Promise.resolve();
for (let index = 0; index < 5; index++) {
p = p.then(() =>
isElementDisplayedAfterrefresh($driver.By.xpath("//span[text()='PouchDB']"), "input"))
.then(a=>$browser.sleep(3000))
.then(()=>$browser.navigate().refresh())
}
return p;
}
).then(
()=>console.log('done'))
code should exit if element is not displayed, it should refresh if element is still displayed. How to loop through promise sequentially when we don't know results/number of iterations the return type is Promise, How to break loop? thanks
Edit
https://gist.github.com/saiparth/045c32267e55b836f139bdac6597e57b Issue is it schedules commands for loop, so all 5 iteration will execute no matter for previous index worked not. Also I should not use async/await