Skip to content

Instantly share code, notes, and snippets.

@nabinno
Created June 23, 2016 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabinno/a121286892c3ecbf6eea74ea905ba4d9 to your computer and use it in GitHub Desktop.
Save nabinno/a121286892c3ecbf6eea74ea905ba4d9 to your computer and use it in GitHub Desktop.
PhantomJS
var page = require('webpage').create();
var system = require('system');
if (system.args.length === 1) {
console.log('Usage: phatomjs warmup-select-condition.js <some URL>');
phantom.exit();
}
var address = system.args[1];
var lib = "//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";
page.onConsoleMessage = function(msg) { console.log("console> " + msg); }
page.open(address, function(status) {
if (status !== 'success') {
console.log('FAIL to warm up the address');
} else {
var t = Date.now();
setTimeout(function() {
page.includeJs(lib, function() {
console.log('----------------------------------------------------------------------');
page.evaluate(function() {
console.log("show_title: " + $("title").text());
console.log("show_button: " + $("button").text());
$("button").click();
});
console.log("time: " + (Date.now() - t) + "ms");
});
}, 0);
setTimeout(function() {
page.includeJs(lib, function() {
console.log('----------------------------------------------------------------------');
page.evaluate(function() {
console.log("show_title: " + $("title").text());
console.log("show_button: " + $("button").text());
$("button").click();
});
console.log("time: " + (Date.now() - t) + "ms");
phantom.exit();
});
}, 3000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment