This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 3
Mar 2016

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#L117329 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

  • created

    Mar '16
  • last reply

    Feb '19
  • 2

    replies

  • 1.6k

    views

  • 2

    users

  • 1

    like

  • 1

    link

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);
    }
2 years later

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.)