mrkeck Sharing the Love

12Nov/120

phantomJs delay until condition is met

var tries=0;
var maxTries=10;
var howOften=2000;
var tom=setInterval(function(){
	tries++;
	delayResponse=page.evaluate(function(){
		//console.log('Searching');
		return $('#thingy').length>0;
	});
	if(delayResponse || maxTries<=tries){
		//console.log('Found it or out of time');
		clearInterval(tom);
		//Do stuff now that it is ready
	}
},howOften);

There is a function out there called waitFor but I found this easier to handle

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.