Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Logging in to Amazon using PhantomJS
// phantomjs code to log in to Amazon
// based on the code from this Stackoverflow answer:
// I'm injecting jQuery so this assumes you have jquery in your project directory
var page = new WebPage(), testindex = 0, loadInProgress = false;
page.onConsoleMessage = function(msg) {
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
var steps = [
function() {
console.log("Load Login Page");
page.settings.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11";"");
function() {
console.log("Enter Credentials");
page.evaluate(function() {
$('#ap_email').val('AMAZON EMAIL ACCOUNT');
$('#ap_password').val('AMAZON PASSWORD');
function() {
page.evaluate(function() {
interval = setInterval(function() {
if (!loadInProgress && typeof steps[testindex] == "function") {
console.log("step " + (testindex + 1));
//page.render("images/step" + (testindex + 1) + ".png");
if (typeof steps[testindex] != "function") {
console.log("test complete!");
}, 50);
Copy link

RauenS commented Oct 20, 2013

Hello!I have a problem.Can you help me(

Copy link

awaisakbar2020 commented Apr 19, 2020

This code is not working its probably because amazon doesn't show both user name and password fields on one page. The first page has a username field while the second is for the password, so there are two forms in total. How to make this code work now? how to login to amazon when we have to submit two forms on two different pages.

Copy link

dariusk commented Apr 27, 2020

Sorry, this was written against a seven-year-old version of the Amazon home page. You'll need to completely rewrite this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment