evaluate

var casper = require('casper').create();

casper.start('http://en.wikipedia.org/', function() {
  this.echo(this.getTitle());
});

casper.then(function () {
    this.echo('Page title using evaluate is: ' + this.evaluate(function () {
        return document.title;
    })); // Will be printed in green on the console
});

The evaluate() Evaluates an expression in the current page DOM context.
Think of the evaluate() method as a gate between the CasperJS environment and the one of the page you have opened; everytime you pass a closure to evaluate(), you’re entering the page and execute code as if you were using the browser console.

Here’s a quickly drafted diagram trying to basically explain the separation of concerns:Click image for reference



Comments

Popular Posts