我有一个包含带有 javascript 设置的 HTML 表单的页面,如果您单击带有 someid 的按钮,表单就会被提交。我通过在浏览器控制台中触发来验证这一点:
document.getElementById("arcotsubmit").click()
一旦它被触发,url 就会改变并提交表单。
现在我尝试用 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();
它停留在同一个 URL 上并下载同一个页面。我想下载 casper 单击按钮后出现的 html。该 URL 是实时的,可以直接测试。
我的意思是我是否可以在浏览器控制台中使用这个命令
document.getElementById("arcotsubmit").click()
并让它重定向,为什么我不能这样做 casperjs 中的 this.click("#arcotsubmit")?
最佳答案
重定向是提交而不是点击。 input[type=image] 的默认事件是提交,所以试试这个:
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();
});
});
会通过的。 Test Result Screen Shot
关于javascript - casperjs 按钮点击不导航到下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21363895/