I use this piece of JS code to login to my bank and get the balance. This code snippet works, but I wanted to know if I could make this code smaller, faster or if I could anything differently to improve it.

casper.start(url, function() {

    console.log("Checking login status @ " + url);

    this.waitForSelector("form[name='SignonForm']", function() {
        this.fill('form#login', {
            'SignonAccountNumber': username,
            'SignonPassword':  password,
        }, true);

casper.then(function() {

    if (/YES/.test(this.getCurrentUrl())) {
        this.thenOpen(this.getCurrentUrl(), function() {
            this.echo("Your balance: " + this.getHTML('#ctl00_wpm_ac_ac_rba_ctl00_dsv'));
    } else {
        this.echo("Looks like the login failed.");



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.