3

I have a page that contains the HTML form with javascript setup like if you click on a button with someid, the form gets submitted. I verified this by firing this in browser console:

document.getElementById("arcotsubmit").click()

As soon as it gets fired, the url changes and form gets submitted.

Now i tried to replicate this with casper.js:

var casper = require('casper').create({});


casper.start('https://cib.icicibank.com/corp/BANKAWAY?Action.CorpUser.Init1.001=Y&AppSignonBankId=ICI&AppType=corporate', function() {
    this.echo(this.getTitle());
});

casper.then(function(){

    this.click("#arcotsubmit");

});

casper.then(function(){

    console.log(this.getCurrentUrl())
});

casper.run();

It stays on the same URL and downloads the same page. I want to download the html that appears after the button gets clicked by casper. The URL is live and can be tested directly.

My point is if i can use this command in browser console

document.getElementById("arcotsubmit").click()

and make it redirect, why i am unable to do it with this.click("#arcotsubmit") in casperjs?

beNerd
  • 3,314
  • 6
  • 54
  • 92

2 Answers2

1

It is submit instead click for redirecting. The default event for input[type=image] is submit so that try this:

casper.test.begin('Test page.', 2, function suite(test) {
    casper.start(
        'https://cib.icicibank.com/corp/BANKAWAY?Action.CorpUser.Init1.001=Y&AppSignonBankId=ICI&AppType=corporate',
        function() {
            this.echo(this.getTitle());
            test.assertUrlMatch(/BANKAWAY?/, 'Current location is ' + this.getCurrentUrl());
        }
    );

    casper.then(function(){
        this.fill('#rt', {}, true);
        this.wait(2000, function() {
            test.assertUrlMatch(/BANKAWAY;/, 'New location is ' + this.getCurrentUrl());
        });
    });

    casper.run(function() {
        test.done();
    });
});

It will be passed. Test Result Screen Shot

Anson
  • 489
  • 7
  • 12
0

Possible quick fix. If Casper's click isn't working, but your code works in console of the browser, try using Casper's evaluate function.

casper.then(function() {
  this.evaluate(function() {
    document.getElementById("arcotsubmit").click();
  });
});
Christopher Ellis
  • 1,106
  • 1
  • 8
  • 12