title: On PhantomJS I can't include jQuery and without jQuery I can't post form data
body: <p>I am having trouble running jQuery in PhantomJS. I have found <a href="https://stackoverflow.com/questions/12555203/phantomjs-does-not-execute-function-in-page-evaluate-function">this</a> answer, which talks about no variable is available inside evaluate function but the question is about a node module and on my example I only call <code>console.log</code> inside evaluate function. I have put this question on <a href="https://github.com/ariya/phantomjs/issues/11211" rel="nofollow noreferrer">GitHub too</a>.</p>
  
  <p>Previously, for some pages, the following <code>evaluate</code> code didn't execute. Now that @b1f56gd4 has provided some help, it now prints messages; I can't execute it but now I can see this:</p>
  
  <blockquote>
    <p>The page at <a href="https://login.yahoo.com/" rel="nofollow noreferrer">https://login.yahoo.com/</a> ran insecure content from <a href="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" rel="nofollow noreferrer">http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js</a>.</p>
  </blockquote>
  
  <p>I can't load jQuery from different domain and the <code>--local-to-remote-url-access=true</code> or <code>--web-security=false</code> options make no difference.</p>
  
  <p>I will try load jQuery locally. Here is the code:</p>
  
  <pre><code>console.log('Loading a 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 is 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'; // to load local
          //jsLoc = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'; // to 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');  // &lt;&lt;&lt;&lt;==== Execute only until here
              console.log('Source:['+jsLoc+']');
              var rs = page.includeJs(jsLoc, function()  // &lt;&lt;&lt;&lt;===== Fail here, jsLoc was changed to load locally and after tried remotely, i tried use page.injectJs but fail too
              { 
                  console.log('JQuery Loaded');  // &lt;&lt;&lt;&lt; ===== Never reach here, no matter if loading local or remote script in include above
                  func(page); 
              });
              page.render('ystsB.png');
          } else {
              console.log('JQuery Already Loaded');
              func(page);
              page.render('ystsC.png');
          }
          //-------------------------------------------------
      }
      phantom.exit();
  });
  </code></pre>
  
  <p>After reading @g4d564w56 answer i did all without JQuery then i can fill textbox but cant click on button to post on login form.<br>
  See the new code:</p>
  
  <pre><code>console.log('Loading a 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 is 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'; // to load local
          //jsLoc = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'; // to 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(); /// &lt;&lt;&lt;&lt;==== now its dont work !!!
                  //---
              });
              console.log('Rendering');
              pg.render('ystsA.png');
              console.log('Rendered');
          }
          act01(page);
          //-------------------------------------------------
      }
      phantom.exit();
  });
  </code></pre>