sheebz / phantom-proxy

a lightweight proxy that lets you to drive phantomjs from node.
MIT License
137 stars 34 forks source link

How to wait for all js to be loaded? #42

Closed toranb closed 11 years ago

toranb commented 11 years ago

I'm loading up some javascript in the page phantom-proxy is opening and I'm not sure how to "waitFor" all the js to be loaded

var phantomProxy = require('phantom-proxy').create({}, function(proxy) {                                                       
  var page = proxy.page;
  phantom = proxy.phantom;

  page.open("http://localhost:8091", function() {
      page.waitForSelector('body', function() {
          //do stuff with jQuery here but its not available yet?
  });
});
});
toranb commented 11 years ago

Also inside the waitForSelector block how can I get to the dom to lookup attributes / other elements on body?

capaj commented 11 years ago

I wait for an element with specific ID- #content for example. Element #content is generated by JS, so I won't get the callback until my JS app is all loaded. You can run page.evaluate(function(){ return x;}, function(x){ //do stuff with returned x here}) to run any javascript on the page.

toranb commented 11 years ago

I could wait for an element as you mentioned but what is the syntax to wait for a div with a specific class? such as

div class="jasmine_reporter"

Also can I do the page.evaulate (as you showed) inside the page.open block or instead of it or ?

toranb commented 11 years ago

Here is what I have currently

(function() {
var app = require('./app.js');

app.webserver.listen(8091);

var phantomProxy = require('phantom-proxy').create({}, function(proxy) {
  var page = proxy.page;
  phantom = proxy.phantom;

  page.open("http://localhost:8091", function() {
      page.waitForSelector('.jasmine_reporter', function(result) {

          page.evaluate(function(){ return x;}, function(x){                                                                           
              console.log(x);
          });

          phantomProxy.end();
      });
  });
});

}).call(this)

Currently the part that says "app.webserver.listen(8091);"

is where I spin up a node based express website hosting just an index.html page (that I can see is working when I pause the process)

Yet I get a 404 -could the internal webserver phantom-proxy is using interrupt this in some way?

Thank you

toranb commented 11 years ago

closing this -no response (upgraded to node-phantom instead)