Skip to content Skip to sidebar Skip to footer

Evaluate In Phantomjs Doesn't Seem To Work

I have a problem with JavaScript magic. When I execute this code: var page = require('webpage').create(); var url='http://google.com'; page.open(url, function (status){ if (statu

Solution 1:

PhantomJS won't log console messages in .evaluate() statements by default. Just include

page.onConsoleMessage = function (msg) {
    console.log(msg);
};

See this page for more details/in-depth example:

http://code.google.com/p/phantomjs/wiki/QuickStart#Code_Evaluation

Solution 2:

From Google Code

Any console message from a web page, including from the code inside evaluate(), will not be displayed by default. To override this behavior, use the onConsoleMessage callback.

Solution 3:

If you only want select logs to come through, you can return the value that you'd like to print.

For example:

console.log(page.evaluate(function() {
    return'2';
});

Post a Comment for "Evaluate In Phantomjs Doesn't Seem To Work"