Sunday, 11 June 2017

Wait for javascript function in nightmare js

I am having trouble with the .wait() function of nightmare js. I am trying to wait for a javascript function to return true and then proceed with the rest of the script. Is there any way to do this because both ways I've tried don't work. Thanks, all help is appreciated.

var ifCompleted = function(){
     for(var i = 0; i < 101; i++){
          if(i == 100){
               return true;
          }
     }

}

nightmare
     .goto('http://www.google.com')
     .wait(function () {
          return typeof ifCompleted() !== undefined;
     })
     .goto('http://www.yahoo.com/')
     .catch(function (error) {
          console.error('Search failed:', error);
     });

The next wait function does not work either.

.wait(function () {
    return (ifCompleted() === true);
})

This does not work either.

.wait(function () {
    return (ifCompleted() != null);
})

This code is hypothetical, .wait(100) is not what I am trying to do



via Noah Cover

No comments:

Post a Comment