Cma*_*mag 6 javascript phantomjs
学习CasperJS
试图理解为什么以下不在控制台中显示我的结果....
输出:
casperjs testcasper.js
Run Code Online (Sandbox Code Playgroud)
[info] [幻影]开始...... [info] [幻影]跑步套房:3个步骤
码:
var casper = require('casper').create({
loadImages: true,
loadPlugins: true,
verbose: true,
logLevel: 'debug',
});
casper.start(url, function() {
this.debugPage();
this.echo("Test echo.");
this.fill('form#LogonForm', {
'username': username,
'password': password,
}, true);
});
casper.then(function() {
casper.echo("I'm loaded.");
});
casper.run(function() {
console.log(this.getCurrentUrl(),'info');
});
//casper.log('this is a debug message', 'debug');
//casper.log('and an informative one', 'info');
//casper.log('and a warning', 'warning');
//casper.log('and an error', 'error');
casper.exit();
Run Code Online (Sandbox Code Playgroud)
casper.exit()必须在执行完所有步骤后异步调用; 在你的脚本中,这给出了:
casper.run(function() {
console.log(this.getCurrentUrl(),'info');
this.exit();
});
Run Code Online (Sandbox Code Playgroud)