screenshot suggests javascript not running and yet it appears to be

32 views
Skip to first unread message

etao...@yahoo.com

unread,
May 13, 2013, 10:13:32 AM5/13/13
to phan...@googlegroups.com
did some experimenting with phantomjs. The problem I have is that the script appears to be receiving all the urls needed from the page , meaning that javascript is functional but when I make the screenshot it shows the page at the begin state (loading...) not the state i expect it to be after my timeout. 

also tried a casper js version with 

casper.waitUntilVisible("#user-menu", function() {this.echo("waitUntilVisible then ");}, function() { this.echo("waitUntilVisible timeout"); }, 100000 ); 

it comes in the timeout case suggesting javascript is not running and yet I see in the trace all necessary urls pass by. 
In a selenium environment above equivalent wait works. Please advise on how to debug this further or what is wrong with this code ... 


phantomjs version
----------------------------


function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);

var page = require('webpage').create();

page.onError = function (msg, trace) {
    console.log(msg);
    trace.forEach(function(item) {
        console.log('  ', item.file, ':', item.line);
    })
}

page.onResourceRequested = function (request) {
    console.log('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
    console.log('Receive ' + JSON.stringify(response, undefined, 4));
};

page.open('http://someip/', function () { 
pausecomp(10000); 
page.render('7.png');
console.log('done');
    phantom.exit();
});



James Greene

unread,
May 22, 2013, 3:31:25 PM5/22/13
to phan...@googlegroups.com
Your `pausecomp` is a busy loop that won't yield and allow QtWebKit to actually run the page's JavaScript.  You need to switch it to an asynchronous model, e.g.

```
page.open('http://someip/', function(status) {
    if (status !== "success") {
        console.error("Page failed to load. Status: " + status);
        phantom.exit(1);
    }
    else {
        setTimeout(function() {
  page.render('7.png');
  console.log('done');
            phantom.exit();
        },10000);
    }
});
```

Sincerely,
    James Greene





--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phantomjs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/phantomjs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages