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();
[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
我的函数返回空值? 救命 ??感谢
答案 0 :(得分:0)
我不使用$(window).load
,而是document.readyState === "complete"
casper.start("http://www.google.com", function(){
this.echo(this.evaluate((function() {
if(document.readyState === "complete") {
return "======Page"+$('title').text()+"=========" ;
}
})));
});