1

Here is my script

var casper = require('casper').create({
   clientScripts: [
     '/Path/to/JQuery/Test/jquery-2.0.3.js'  
   ],
   logLevel: "info",             
   logLevel: "debug",
   verbose: true
});

casper.start("http://www.google.com", function(){
    console.log(this.evaluate((function() {
        $( window ).load(function(){
            return "======Page"+$('title').text()+"=========" ;
        });    
    })));  
});

casper.run();

Result in console

[info] [phantom] Step anonymous 2/2 http://www.google.com/ (HTTP 200)

null

[debug] [phantom] Automatically injected /Path/to/JQuery/Test/jquery-2.0.3.js client side
[debug] [phantom] Automatically injected /Path/to/JQuery/Test/jquery-2.0.3.js client side
[info] [phantom] Done 2 steps in 1154ms

My function returns a null value? Help ?? Thanks

vinczemarton
  • 7,756
  • 6
  • 54
  • 86
  • I'm similarly having a ton of trouble getting PhantomJS and CasperJS to wait for a full page load. I'm trying to follow this advice: http://stackoverflow.com/a/27472788/470749 – Ryan May 25 '16 at 17:36

1 Answers1

0

I don't use $(window).load but document.readyState === "complete"

casper.start("http://www.google.com", function(){
    this.echo(this.evaluate((function() {
        if(document.readyState === "complete") {
            return "======Page"+$('title').text()+"=========" ;
        }
    })));
});
EpokK
  • 38,062
  • 9
  • 61
  • 69