Thank you! Your feedback has been delivered
Thank you! Your feedback has been sent

Evaluate function is not getting executed

Please see my code as below

I have used Evaluate as shown in bold in the code. But on executing the code it does not execute evaluate.

var fs = require('fs');
var casper = require('casper').create();
casper.on('remote.message', function (msg) {
    this.echo(msg);
});
casper.start();
casper.options.waitTimeout = 100000;
casper
  .then(function(){
    console.log("Start:");
  })
  .thenOpen("http://www.lenskart.com/vincent-chase-60168-matt-black-grey-aviator-polarized-sunglasses.html")
  .then(function(){
    // scrape something
    this.echo(this.getTitle());
  })
  .thenClick("#alone_add_button")
  .then(function(){

var couponInformations = this.evaluate(test, 'test'); console.log('strt');
this.waitUntilVisible('#slideShoppingCart', function() { console.log('close ');
}); });

casper.run(function () {

this.exit();
});

function test(test){
    console.log("inside test finally");
    return 'y';
}
User Gravatar

user352

Posted Sep 2 2013 11:53 UTC

$5


  • 1411 Views

2 Replies


Hi mate - the following works in my environment, simply put you should use the call() function. This example below will return the following :- inside test finally

function test(test){
  console.log("inside test finally");
  casper.exit();
}

var fs = require('fs');
var casper = require('casper').create();
casper.on('remote.message', function (msg) {
  this.echo(msg);
});

casper.start();
casper.options.waitTimeout = 100000;
casper.then(function(){
  console.log("Start:");
})

.thenOpen("http://www.lenskart.com/vincent-chase-60168-matt-black-grey-aviator-polarized-sunglasses.html")
.then(function(){
  // scrape something
  this.echo(this.getTitle());
})

.thenClick("#alone_add_button")
.then(function(){
    //var couponInformations = this.evaluate(test, 'test'); console.log('strt');
    test.call(this);                        
    this.waitUntilVisible('#slideShoppingCart', function() { console.log('close ');
    }); 
});

casper.run();
User Gravatar

zabius

Posted Sep 2 2013 16:18 UTC

Basically I want to execute a javascript function test. That is why am using evaluate. I want to use console.log inside evaluate

User Gravatar

user352

Posted Sep 2 2013 20:52 UTC

Add a reply

By posting a reply on CodersClan you agree to our Terms & Conditions