casperJS 未记录到控制台

发布于 2024-12-28 19:40:56 字数 875 浏览 4 评论 0原文

学习 CasperJS

试图理解为什么以下内容没有在控制台中显示我的结果...

输出:

casperjs testcasper.js 

[info] [phantom]开始... [info] [phantom] 运行套件: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();

Learning CasperJS

Trying to understand why the following is not displaying my results in the console....

output:

casperjs testcasper.js 

[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps

code:

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉态萌生 2025-01-04 19:40:56

casper.exit() 必须在执行完所有步骤之后异步调用;在你的脚本中,这给出了:

casper.run(function() {
    console.log(this.getCurrentUrl(),'info'); 
    this.exit();
});

casper.exit() must be called asynchronously after all the steps having been executed; in your script, this gives:

casper.run(function() {
    console.log(this.getCurrentUrl(),'info'); 
    this.exit();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文