[英]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.