Skip to content

Instantly share code, notes, and snippets.

@marcioferreira
Forked from n1k0/casperjs-link-checker.md
Last active August 29, 2015 14:08
Show Gist options
  • Save marcioferreira/7435009a90ca2050f8a1 to your computer and use it in GitHub Desktop.
Save marcioferreira/7435009a90ca2050f8a1 to your computer and use it in GitHub Desktop.
/*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