Casperjs - trying to run casper script from command line doesn't output correctly

人盡茶涼 提交于 2020-01-06 08:16:19

问题


I'm brand new to casperjs, and in the process of trying to run my first casper script from the command line (using $ casperjs sample.js), I received this output:

Casper CLI passed args:
[]
Casper CLI passed options:
{
    "casper-path": "/usr/local/Cellar/casperjs/1.1-beta2/libexec",
    "cli": true
}

Instead of the predicted output of:

CasperJS, a navigation scripting and testing utility for PhantomJS
PhantomJS: Headless WebKit with JavaScript API

Here are the contents of the sample file:

var casper = require('casper').create();

casper.start('http://casperjs.org/', function() {
    this.echo(this.getTitle());
});

casper.thenOpen('http://phantomjs.org', function() {
    this.echo(this.getTitle());
});

casper.run();

I installed casperjs using the latest version of homebrew.

Any help is much appreciated. Thanks in advance.


回答1:


It looks like you aren't running the sample that you think you are.

The output you gave came from this code:

var casper = require("casper").create();

casper.echo("Casper CLI passed args:");
require("utils").dump(casper.cli.args);

casper.echo("Casper CLI passed options:");
require("utils").dump(casper.cli.options);

casper.exit();

You could try running less sample.js to verify the contents of sample.js.

Source



来源:https://stackoverflow.com/questions/21125834/casperjs-trying-to-run-casper-script-from-command-line-doesnt-output-correctl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!