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.2 $ 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.2
You are now ready to write your first script!
casperjs executable is written in Python, so please ensure
that a Python interpreter is available on your platform.
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.2 at /Users/niko/Sites/casperjs, using PhantomJS version 1.7.0 ...
CasperJS on Windows
Phantomjs installation additions
";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.
";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.2'; phantom.injectJs(phantom.casperPath + '\\bin\\bootstrap.js'); var casper = require('casper').create(); // do stuff
Run the script using the
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.