Skip to content

Instantly share code, notes, and snippets.

@n1k0
Last active August 5, 2016 04:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save n1k0/4391477 to your computer and use it in GitHub Desktop.
Save n1k0/4391477 to your computer and use it in GitHub Desktop.
A link checker using CasperJS
/*jshint strict:false*/
/*global CasperError console phantom require*/
var casper = require('casper').create({
logLevel: "debug",
verbose: true
}),
interval = 1000 * 60, // 1 minute
url = 'http://google.com/'; // URL to check
casper.checkLink = function checkLink() {
this.echo('Setting up check steps...');
this.open(url).then(function() {
if (this.exists('#selector-to-your-link')) {
this.echo('link was found, clicking');
this.thenClick('#selector-to-your-link').then(function() {
// add stuff to be done
// ... then exit
this.echo('Done.').exit();
});
} else {
this.warn('Link not found, scheduling another attempt');
this.wait(interval);
}
});
this.run(this.checkLink);
};
casper.start().checkLink();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment