简体   繁体   中英

CasperJS timeout while logging into a bank account

I'm attempting to login to a Capital One 360 bank account using CasperJS. It loads the username screen, properly enters a username, loads the password screen, but then times-out (presumably, there's no error) and stops after entering the password.

Anyone have any ideas as to what I'm doing wrong?

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});

var capone360 = "https://secure.capitalone360.com/myaccount/banking/login.vm";

casper.start(capone360);

casper.then(function(){
   casper.waitForSelector("#ACNID", function() {
        this.echo(this.getTitle());
        this.sendKeys('#ACNID', username);
    }, true); 
});

casper.then(function(){
    this.click("#btn_continue"); 
});

casper.then(function(){
    this.waitForSelector("#currentPassword_TLNPI", function() {
        this.echo(this.getTitle());
        this.sendKeys('#currentPassword_TLNPI', password);
    }, true);
});

casper.then(function(){
    this.clickLabel("Continue", "a");
});

casper.then(function(){
    this.waitForSelector("#deposittable", function() {
        this.echo(this.getTitle());
    }, true);
});

casper.run();

PhantomJS version 2.0.0

Update Switched to PhantomJS 1.9.8. per @Artjom B. suggestion. Now there are errors saying: 'Cannot dispatch mousedown event on nonexistent selector: xpath selector: //a[text()="Continue"]'.

It's attempting to click:

<a class="ada-new-win" href="javascript:void(0);" role="button" onclick="submitForm('continue'); return false;">Continue</a>

I assumed it should be there given that it's waited for the password input box to load, but am I forgetting something else?

PhantomJS 2.0.0 has a bug where errors are not printed to the console even when specifically listening to the various error events. That is why you don't see the obvious error which would go something like this:

TypeError: true is not a function

The reason for that error is that you're providing true as a third parameter for waitForSelector() , but the function signature is

waitForSelector(String selector[, Function then, Function onTimeout, Number timeout])

It seems that some step in your script breaks, because a selector cannot be found. The passed function for onTimeout will be executed, but true is not a function. Simply remove the third parameter to see where the error lies. If still nothing is shown, try using PhantomJS 1.9.8.


You either need to wait for the "Continue" button to appear using waitForSelector(x(selector)) and/or you need to use a more robust selector:

var x = require("casper").selectXPath;
...
var continueButtonSelector = x("//a[contains(text(), 'Continue')]");
casper.waitForSelector(continueButtonSelector);
casper.thenClick(continueButtonSelector);

This is sometimes necessary, because the element is probably defined with whitespace like this

<a>   Continue   </a>
   ^^^        ^^^

which means that text()="Continue" cannot match. The browser renderer disregards this whitespace, but it is still in the DOM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM