- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
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