2013-07-31 42 views
1

我使用CasperJS來填寫一些表單(輸入字段,選擇框等)。我已經將jquery注入腳本,但我不知道如何獲取它的其餘部分加工。與jQuery一起使用casperjs來填寫表格

我基本上試圖'找到'頁面上的單個元素,並在其中找到標籤並更改值。一旦這個改變了,我想單擊具有'add_phone'的html名稱的提交按鈕。

這裏是我迄今爲止 - 請注意我用的是最新版本1.1.0 CasperJS-DEV與PhantomJS v1.9.1的

這在執行時返回以下錯誤:

TypeError: 'undefined' is not a function (evaluating 'this.evaluate(function() { 
    return $('table').find('select').val(); 
}); 

代碼:

var casper = require('casper').create({ 
    clientScripts: ['includes/jquery.min.js'], 
    verbose: true, 
    logLevel: 'debug', 
    loadImages: false 
}); 

var url = 'http://www.simplysellular.com/displayphone.php?manufacturers=Apple&phones=iPhone+5+(ATT/GSM)+32GB&affiliates_id=14&affiliates_tracking_id=2072&utm_source=sellcell&utm_medium=web&utm_campaign=sellcell&condition_id=15'; 
casper.start(url); 

var deviceValue = this.evaluate(function() { 
return $('table').find('select').val(); 
}); 

this.echo(deviceValue); 

casper.exit(); 

回答

4

this任何職能是casperjs undefined

試試casper.then

casper.start(url); 
casper.then(function() { 
    var deviceValue = this.evaluate(function() { 
    return $('table').find('select').val(); 
    }); 
    this.echo(deviceValue); 
});