2014-01-26 73 views
3

我有一個頁面,其中包含與JavaScript設置的HTML表單,如果你點擊一個按鈕與someid,表單被提交。我在瀏覽器控制檯射擊這驗證了這一點:casperjs按鈕點擊不會導航到下一頁

的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」)做呢?

+0

你有沒有找到解決方案,因爲我有同樣的問題?而且,我正在使用PhantomJS。 – alphadogg

回答

0

可能的快速修復。如果卡斯帕的點擊不起作用,但是您的代碼在瀏覽器的控制檯中工作,請嘗試使用卡斯帕的evaluate功能。

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

naah其相同的事情。不工作:( – beNerd

0

這是提交代替點擊重定向。對於輸入[類型=圖片]是默認的事件提交讓試試這個:

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