Skip to content

Instantly share code, notes, and snippets.

@bigprof
Created June 22, 2016 19:44
Show Gist options
  • Save bigprof/a82bc7af046c3d886c444e6b2cc2616c to your computer and use it in GitHub Desktop.
Save bigprof/a82bc7af046c3d886c444e6b2cc2616c to your computer and use it in GitHub Desktop.
Automating phantomJS using jQuery
/*
To automate phantomjs using jQuery
See also: https://github.com/ariya/phantomjs/blob/master/examples/page_events.js
*/
var url = 'http://www.sample.com'; // start url
var eval_code = function() {
// code to execute here. Use 'page' instance to navigate to other urls if needed
$("button").click();
}
/*****************************************************/
var page = require('webpage').create(),
on_open = function(){
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", on_jquery);
},
on_jquery = function(){
page.evaluate(eval_code);
phantom.exit();
};
page.open(url, on_open);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment