Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created April 29, 2016 23:09
Show Gist options
  • Save ahgood/ba3d163d160a747c664f4b939fd55c89 to your computer and use it in GitHub Desktop.
Save ahgood/ba3d163d160a747c664f4b939fd55c89 to your computer and use it in GitHub Desktop.
PhantomJS sample script
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open("http://www.somewebsite.com", function(status) {
if ( status === "success" ) {
page.evaluate(function() {
document.querySelector("input[name='MAIL_ADDRESS']").value = "[email protected]";
document.querySelector("input[name='PASSWORD']").value = "mypassword";
document.getElementsByName("LOGIN_FORM_SUBMIT")[0].click();
console.log("Login submitted!");
});
window.setTimeout(function () {
page.render('screenshot.png');
var ua = page.evaluate(function () {
return document.getElementById('AnElementIdOnMyWebsite').innerText;
});
console.log(ua);
phantom.exit();
}, 5000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment