javascript - PhantomJs example not working? -


can please tell me why example in below link not working. added timeout 12 seconds. showing me => console.log("'waitfor()' timeout");

link: https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js

i copied example not working. trying run using 'phantomjs'. can please guide me possible reasons?

phantomjs version: 2.1.1

i have modified script, , it's working:

/**  * wait until test condition true or timeout occurs. useful waiting  * on server response or ui change (fadein, etc.) occur.  *  * @param testfx javascript condition evaluates boolean,  * can passed in string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or  * callback function.  * @param onready when testfx condition fulfilled,  * can passed in string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or  * callback function.  * @param timeoutmillis max amount of time wait. if not specified, 3 sec used.  */  "use strict"; function waitfor(testfx, onready, timeoutmillis) {     var maxtimeoutmillis = timeoutmillis ? timeoutmillis : 5000, //< default max timout 3s         start = new date().gettime(),         condition = false,         interval = setinterval(function() {             if ( (new date().gettime() - start < maxtimeoutmillis) && !condition ) {                 // if not time-out yet , condition not yet fulfilled                 condition = (typeof(testfx) === "string" ? eval(testfx) : testfx()); //< defensive code             } else {                 if(!condition) {                     // if condition still not fulfilled (timeout condition 'false')                     console.log("'waitfor()' timeout");                     phantom.exit(1);                 } else {                     // condition fulfilled (timeout and/or condition 'true')                     console.log("'waitfor()' finished in " + (new date().gettime() - start) + "ms.");                     typeof(onready) === "string" ? eval(onready) : onready(); //< it's supposed once condition fulfilled                     clearinterval(interval); //< stop interval                 }             }         }, 250); //< repeat check every 250ms };   function click(sel){var event=document.createevent('mouseevents');event.initmouseevent('click',1,1,window,1,0,0,0,0,0,0,0,0,0,null);document.queryselector(sel).dispatchevent(event);} var page = require('webpage').create();  // open twitter on 'sencha' profile and, onpageload, do... page.open("https://twitter.com/sencha", function (status) {     // check page load success     if (status !== "success") {         console.log("unable access network");     } else {        page.evaluate(function(click) {click('a[id="signin-link"]');},click)//,click available         // wait 'signin-dropdown' visible         waitfor(function() {             // check in page if specific element visible             return page.evaluate(function() {                 return $("div#signin-dropdown").is(":visible");             });         }, function() {            console.log("the sign-in dialog should visible now.");            phantom.exit();         });     } page.render('sencha.png');  }); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -