javascript - On PhantomJS I can't include jQuery and without jQuery I can't post form data -


i having trouble running jquery in phantomjs. have found this answer, talks no variable available inside evaluate function question node module , on example call console.log inside evaluate function. have put question on github too.

previously, pages, following evaluate code didn't execute. @b1f56gd4 has provided help, prints messages; can't execute can see this:

the page @ https://login.yahoo.com/ ran insecure content http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js.

i can't load jquery different domain , --local-to-remote-url-access=true or --web-security=false options make no difference.

i try load jquery locally. here code:

console.log('loading web page'); var url = 'https://login.yahoo.com/';  var page = require('webpage').create(); console.log('setting error handling'); page.onconsolemessage = function (msg) {     console.log(msg); }; page.onerror = function (msg, trace) {     console.log(msg);     trace.foreach(function(item) {         console.log('  ', item.file, ':', item.line);     })     phantom.exit(); } console.log('error handling set'); console.log('opening page'); page.open(url, function (status) {     if (status != 'success') {         console.log('f-' + status);     } else {         console.log('s-' + status);          //-------------------------------------------------              var jsloc = '';         jsloc = 'jquery.min.js'; // load local         //jsloc = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'; // load remote         var func = function(pg){             console.log('function called');             console.log('page evaluating');             console.log(pg);             pg.evaluate(function() {                 console.log('page evaluate started');                                //---                 var loginvar = 'ih5d4hf65465fd45h6@yahoo.com.br';                 var pwdvar = 'itsmypass_445f4hd564hd56f46s';                  //---                 $("#login_form #username").value = loginvar;                 $("#login_form #passwd").value = pwdvar;                 //---             });             console.log('rendering');             pg.render('ystsa.png');             console.log('rendered');         }         if (typeof jquery == 'undefined') {               console.log('jquery loading');  // <<<<==== execute until here             console.log('source:['+jsloc+']');             var rs = page.includejs(jsloc, function()  // <<<<===== fail here, jsloc changed load locally , after tried remotely, tried use page.injectjs fail             {                  console.log('jquery loaded');  // <<<< ===== never reach here, no matter if loading local or remote script in include above                 func(page);              });             page.render('ystsb.png');         } else {             console.log('jquery loaded');             func(page);             page.render('ystsc.png');         }         //-------------------------------------------------     }     phantom.exit(); }); 

after reading @g4d564w56 answer did without jquery can fill textbox cant click on button post on login form.
see new code:

console.log('loading web page'); var url = 'https://login.yahoo.com/';  var page = require('webpage').create(); console.log('setting error handling'); page.onconsolemessage = function (msg) {     console.log(msg); }; page.onerror = function (msg, trace) {     console.log(msg);     trace.foreach(function(item) {         console.log('  ', item.file, ':', item.line);     })     phantom.exit(); } console.log('error handling set'); console.log('opening page'); page.open(url, function (status) {     if (status != 'success') {         console.log('f-' + status);     } else {         console.log('s-' + status);          //-------------------------------------------------              var jsloc = '';         jsloc = 'jquery.min.js'; // load local         //jsloc = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'; // load remote               var act01 = function(pg){             console.log('function called');             console.log('page evaluating');             console.log(pg);             pg.evaluate(function() {                 var getelmbyid = function(id){                     return document.getelementbyid(id);                 }                            console.log('page evaluate started');                               //---                 var loginvar = 'ih5d4hf65465fd45h6@yahoo.com.br';                 var pwdvar = 'itsmypass_445f4hd564hd56f46s';                  //---                 getelmbyid("username").value = loginvar;                 getelmbyid("passwd").value = pwdvar;                 getelmbyid("login_form").submit(); /// <<<<==== dont work !!!                 //---             });             console.log('rendering');             pg.render('ystsa.png');             console.log('rendered');         }         act01(page);         //-------------------------------------------------     }     phantom.exit(); }); 

i know question has been answer year ago, answer didn't address issue. reason error below:

"the page @ https://login.yahoo.com/ ran insecure content http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js."

is login page https page , you're trying load http resource. if change url https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js error go away. took while figure out.


Comments