繁体   English   中英

casperjs按钮单击不导航到下一页

[英]casperjs button click doesn't navigate to next page

我有一个页面,其中包含带有javascript设置的HTML表单,如果您单击带有someid的按钮,表单将被提交。 我在浏览器控制台中解决了这个问题:

的document.getElementById( “arcotsubmit”)。点击()

一旦被触发,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”)来做它?

它是提交而不是点击重定向。 输入[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();
    });
});

它将通过。 测试结果屏幕截图

可能的快速修复。 如果Casper的点击不起作用,但您的代码在浏览器的控制台中工作,请尝试使用Casper的评估功能。

casper.then(function() {
  this.evaluate(function() {
    document.getElementById("arcotsubmit").click();
  });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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