Define Page Evaluate Outside Of Page Open In Phantomjs
in the basic example of open a web page with phantomjs we use below code for open web and evaluate when page open complete in a function . var page = require('webpage').create();
Solution 1:
not sure what exactly do you mean, but from what I've understood from your example this could help maybe:
var page = require('webpage').create();
// document is already initializeddocument.title = 'internal call';
page.onConsoleMessage = function (msg, lineNum, sourceId) {
console.log('PAGE\'S CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
var func = function () {
console.log('Title: ', document.title);
}
// calling outside of the page.open:func();
page.open('http://google.com/', function () {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function () {
// calling inside:
page.evaluate(func);
page.close();
phantom.exit(0);
});
});
Also there is a Note for page.evaluate function about arguments and closures
Post a Comment for "Define Page Evaluate Outside Of Page Open In Phantomjs"