2014-11-06 42 views

回答

1

你不能從casper.thenEvaluate返回任何東西。它將被忽略。您需要將它分成casper.thencasper.evaluate。請參閱this question瞭解相似的內容。

casper.thenEvaluate是一個異步步進功能,就像所有其他then*wait*函數一樣。從異步函數返回有用的東西是不可能的。你最有可能想要的是這樣的:

var something; 
casper.start(url).then(function(){ 
    something = this.evaluate(function(){ 
     return 'foobar'; 
    }); 
    this.click("someSelector"); 
}).then(function(){ 
    // do something with "something" on the new page 
}); 

我懷疑你就不會問,如果你不想以後使用something。所有步驟函數都會返回初始的casper對象,以便可以像上例中那樣使用promise語法編寫腳本。

相關問題