getting Promise { <pending> } inside a loop
Hi I am very new to Javascript async await I am trying to do mobile automation and I need a do while loop to swipe if the element does not exist. however I am getting Promise { <pending> } when calling a function inside the loop. I believe that I need to resolve the promise in order for me to get the actual result. I've tried to search forums but no luck in finding the solution. I hope this is the correct forum. Please see the code below:
This is the function to check if the element exist:
async isExist(locator) {
return this.client.isVisible(locator);
}
And this is my loop:
async searchElement(locator) {
let lookForElement;
let limitCounter;
do {
lookForElement = this.client.isVisible(locator);
limitCounter = this.client.isVisible(locator);
if (lookForElement === false) {
this.swipe(81, 700, 81, 682);
this.pauseForInSeconds(0.7);
} else {
this.clickOn(locator);
break;
}
} while (limitCounter === false);
the issue is lookForElement and limitCounter will return Promise { <pending> } it will be solved by appending await in this.client.isVisible(locator); function but ESLint will detect an await inside a loop. maybe someone could help me with this matter. Thanks alot.
it will be solved by appending
awaitinthis.client.isVisible(locator);function but ESLint will detect anawait inside a loop
So the problem is not within the Node.js, but with ESLint being incapable to detect it as a valid code. Using await inside loops is perfectly fine, and it is exactly what you want to do here.