Waiting for an element to get displayed in appium with javascript

I want to wait for a Resend button which appears after a timer of 30 seconds runs.
In wd.js library I found the following syntax:

waitForElementById(value, asserter, timeout, pollFreq, cb) 

Can anyone tell me what to use in asserter?

The asserter is a failure that would break the wait. It’s not commonly used. So if you were waiting for an element on the screen, but the screen itself is not correct you might specify an ‘isDisplayed’ type of assertion.

In english, that would be, ‘don’t wait for an element on a screen that isn’t being displayed’.

Commonly you can just skip the asserter. I think this method is overridden so that you could do something like:

waitForElementById(value) or waitForElementById(value, timeout)

Example here:

Tried the suggested thing.Waiting for Resend button which comes after 31 seconds of timer:

      exports.waitForResendButton = function(driver, callback){
         return driver.waitForElementById(this.resendOrCallButton, 32000)
          .then(function(err, res){
             return callback(err, res)
          }) 
       }

But the driver quits without waiting for 32 secs.

1 Like

I was able to figure it out:

var asserters = wd.asserters;
return driver.waitForElementById(id, asserters.isDisplayed, 10000, 100)
then(function(el){
return el.click())

The above function waits for an element to be displayed for 10 seconds pinging every 100ms and once isDisplayed returns true it clicks on the element.

2 Likes

driver.waitForElementById(id, asserters.isDisplayed, 10000, 100); worked for me on wd (Node.JS)
Thanks