Created
June 22, 2016 19:44
-
-
Save bigprof/a82bc7af046c3d886c444e6b2cc2616c to your computer and use it in GitHub Desktop.
Automating phantomJS using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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