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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With