Fork me on GitHub

PhantomJS >= 1.6 must be installed on your system (1.7 recommended). Check out PhantomJS' installation instructions, and:

  • Ensure to always install the latest stable version of PhantomJS;

  • Ubuntu users Double check the version of PhantomJS provided by your apt repository, if any. Often, only old versions are provided.

  • OSX users If you use Homebrew, you can install both CasperJS and PhantomJS using this command:

    $ brew install casperjs

Installation can be achieved using git:

$ git clone git://github.com/n1k0/casperjs.git
$ cd casperjs
$ git checkout tags/1.0.0-RC6
$ ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs

Once PhantomJS and CasperJS installed on your machine, you should obtain something like this:

$ phantomjs --version
1.7
$ casperjs --version
1.0.0-RC6

You are now ready to write your first script!

Note The casperjs executable is written in Python, so please ensure that a Python interpreter is available on your platform.

Ruby version

Added in 1.0 A Ruby version of the casperjs executable is also available in the rubybin/ directory; in order to use the ruby version instead of the python one:

$ ln -sf `pwd`/rubybin/casperjs /usr/local/bin/casperjs

Or using the ruby interpreter:

$ ruby /path/to/casperjs/rubybin/casperjs
CasperJS version 1.0.0-RC6 at /Users/niko/Sites/casperjs, using PhantomJS version 1.7.0
...

CasperJS on Windows

Phantomjs installation additions

Append ";C:\phantomjs" to your PATH environment variable. Modify this path appropriately if you installed PhantomJS to a different location.

Casperjs installation additions

Added in 1.0 CasperJS, as of 1.0.0-RC3, ships with a Batch script so you don't need Python nor Ruby to use it.

Append ";C:\casperjs\batchbin" to your PATH environment variable. Modify this path appropriately if you installed CasperJS to a different location.

You can now run any regular casper scripts that way:

C:> casperjs.bat myscript.js

Earlier versions of CasperJS

Before 1.0.0-RC3, you had to setup your casper scripts that way:

phantom.casperPath = 'C:\\casperjs-1.0.0-RC6';
phantom.injectJs(phantom.casperPath + '\\bin\\bootstrap.js');

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

// do stuff

Run the script using the phantom.exe program:

C:> phantomjs.exe myscript.js

Note There is no output coloration when running CasperJS on Microsoft platforms.

Known Bugs & Limitations

- Due to its asynchronous nature, CasperJS doesn't work well at all with PhantomJS' REPL.

Contribute!

Feel free to play with the code and report any issue on github. CasperJS has also its own on twitter account.