lib/webpage.js
function (selector, callbackFn, timeout) {
                    var self = this,
                        startTime = Date.now(),
                        timeoutInterval = 150,
                        testRunning = false,
                    //if evaluate succeeds, invokes callback w/ true, if timeout,
                    // invokes w/ false, otherwise just exits
                        testForSelector = function () {

                            var elapsedTime = Date.now() - startTime;

                            if (elapsedTime > timeout) {
                                self.options.debug && console.log('warning: timeout occurred while waiting for selector:"%s"'.yellow, selector);
                                callbackFn(false);
                                return;
                            }

                            self.evaluate(function (selectorToEvaluate) {
                                return document.querySelectorAll(selectorToEvaluate).length;
                            }, function (result) {
                                testRunning = false;
                                if (result > 0) {//selector found
                                    callbackFn(true);
                                }
                                else {
                                    setTimeout(testForSelector, timeoutInterval);
                                }
                            }, selector);
                        };

                    timeout = timeout || 10000; //default timeout is 2 sec;
                    setTimeout(testForSelector, timeoutInterval);
                }
function (selector, callbackFn, timeout) {
                    var self = this,
                        startTime = Date.now(),
                        timeoutInterval = 150,
                        testRunning = false,
                    //if evaluate succeeds, invokes callback w/ true, if timeout,
                    // invokes w/ false, otherwise just exits
                        testForSelector = function () {

                            var elapsedTime = Date.now() - startTime;

                            if (elapsedTime > timeout) {
                                self.options.debug && console.log('warning: timeout occurred while waiting for selector:"%s"'.yellow, selector);
                                callbackFn(false);
                                return;
                            }

                            self.evaluate(function (selectorToEvaluate) {
                                return document.querySelectorAll(selectorToEvaluate).length;
                            }, function (result) {
                                testRunning = false;
                                if (result > 0) {//selector found
                                    callbackFn(true);
                                }
                                else {
                                    setTimeout(testForSelector, timeoutInterval);
                                }
                            }, selector);
                        };

                    timeout = timeout || 10000; //default timeout is 2 sec;
                    setTimeout(testForSelector, timeoutInterval);
                }
function ( selector , callbackFn , timeout ) { var self = this , startTime = Date . now ( ) , timeoutInterval = 150 , testRunning = false , //if evaluate succeeds, invokes callback w/ true, if timeout, // invokes w/ false, otherwise just exits testForSelector = function ( ) { var elapsedTime = Date . now ( ) - startTime ; if ( elapsedTime > timeout ) { self . options . debug && console . log ( 'warning: timeout occurred while waiting for selector:"%s"' . yellow , selector ) ; callbackFn ( false ) ; return ; } self . evaluate ( function ( selectorToEvaluate ) { return document . querySelectorAll ( selectorToEvaluate ) . length ; } , function ( result ) { testRunning = false ; if ( result > 0 ) { //selector found callbackFn ( true ) ; } else { setTimeout ( testForSelector , timeoutInterval ) ; } } , selector ) ; } ; timeout = timeout || 10000 ; //default timeout is 2 sec; setTimeout ( testForSelector , timeoutInterval ) ; }
additional methods not in phantomjs api waits for selector to appear, then executes callbackFn
additional methods not in phantomjs api waits for selector to appear then executes callbackFn