Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.