Can someone give me an full example of waiting till an element disappears with Mocha, JS, WD?
I have tried a few approaches but all of them wait till the full implicit timeout and then just fail.
https://github.com/admc/wd/blob/222a1615c244f6e562939ea86815c2d391b2be5e/lib/commands.js#L1173 and several others, so hoping to get a full example
My use case I have to wait till the loader (Activity indicator/ progress indicator) finishes showing up on the screen before I can proceed with my next locators
This is what I came up with eventually. Note that we need both setImplicitWaitTimeout and Q.delay
async function waitTillProgressBarDisappears(max_attempts=10){
await driver.setImplicitWaitTimeout(MOCHA_IMPLICIT_TIMEOUT/10);
let cond = await driver.hasElementByClassName('android.widget.ProgressBar');
console.log(`element found -> ${cond}`)
while(max_attempts > 0 && cond == true){
await Q.delay(MODERATE_WAIT_TIME);
console.log('attempts left', max_attempts)
cond = await driver.hasElementByClassName('android.widget.ProgressBar');
console.log(`element found inside -> ${cond}`)
max_attempts--;
}
console.log(`existing with -> ${cond}`)
await driver.setImplicitWaitTimeout(MOCHA_IMPLICIT_TIMEOUT);
}
1 Like
A lovely workaround, works awesome, even as-is. Thanks!
I did not understand what is the purpose of await Q.delay(MODERATE_WAIT_TIME);
, so I tried removing it. Works good even without (although my program might look WAY different, maybe the statement it is need in yours.)