PhantomJS not running Javascript
I think it should be a good habit to be sure that page is fully loaded when working with javascript. So, probably the answer is here: phantomjs not waiting for "full" page load
Comments
-
Jimmie almost 2 years
I have a html page that can be accessed with the help of xampp locally on, http://localhost/testingserver/trelloapi.html.
That page looks like this, when opened in chrome this page loads fine and a card is created on my trello list. I swapped out the my_key etc so in my version I have in its place a long 12345abcsd...
trelloapi.html
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="https://api.trello.com/1/client.js?key={my_key}&token={my_token}"></script> </head> <body> <script type="text/javascript"> var myList = "{my_listId}"; var creationSuccess = function(data) { console.log('Card created successfully. Data returned:' + JSON.stringify(data)); }; var newCard = { name: 'Making card from console 0.o', desc: 'This is the description of our new card.', // Place this card at the top of our list idList: myList, pos: 'top' }; Trello.post('/cards/', newCard, creationSuccess); </script> </body> </html>
But when I use PhantomJS with the following code, from http://phantomjs.org/ a card is not created on Trello
phantomcall.js
// Simple Javascript example console.log('Loading a web page'); var page = require('webpage').create(); var url = 'http://localhost/testingserver/trelloAPI.html'; page.open(url, function (status) { console.log(status); //Page is loaded! phantom.exit(); });
I downloaded the phantomjs-2.1.1-macosx.zip containing a bin/phantomjs and use the command in terminal: $ sudo ./phantomjs ../../../Desktop/testingServer/phantomcall.js
and the following is printed in console:
Loading a web page
success