PhantomJS - evaluateJavascript()
The evaluateJavaScript method helps to execute the function passed to it as a string. Please note the string passed has to be a function only.
Syntax
Its syntax is as follows −
evaluateJavaScript(str);
Example
Let us take an example to understand the use of evaluateJavaScript() method.
var wpage = require('webpage').create();
wpage.open('http://localhost/tasks/test.html', function(status) {
var script1 = "function(){ var a = document.title; return a;}";
var value = wpage.evaluateJavaScript(script1);
console.log(value);
phantom.exit();
});
The above program generates the following output.
Welcome to phantomjs
phantomjs_webpage_module_methods.htm
Advertisements