2012-07-09 204 views
0

我想填寫表格並提交。CasperJS的填充方法

檢查我的腳本的一部分:

casper.then(function(){ 
    if(this.exists('#msisdn')){ 
     this.echo('ok found'); 
     **this.test.assertExists('form[id="internetPlus"]', 'form is found'); 
     this.fill('form[id="internetPlus"]', { 
      'numero': 'xxxxxxxx' 
     },true);** 
     this.click('#button'); 

而且我得到了這個錯誤:因爲斷言結果是正常

**PASS form is found** 
[info] [remote] attempting to fetch form element from selector: 
'form[id="internetPlus"]' 
**[error] [remote] TypeError: 'undefined' is not an object (evaluating 
'field.getAttribute') 
FAIL CasperError: Unable to fill form 
# type: uncaughtError 
# error: "CasperError: Unable to fill form" 
CasperError: Unable to fill form            
    /home/soufyan/workspace/casperjs:524 in fill 
    /home/soufyan/workspace/casperjs/kkostoreHomeTest.js:45 
    /home/soufyan/workspace/casperjs:909 in runStep 
    /home/soufyan/workspace/casperjs:252 in checkStep** 

我不明白爲什麼我不能填寫表格。

+0

剛剛添加適當的異常拋出時,這種錯誤發生https://github.com/n1k0/casperjs/commit/78683e2cbf78c9993eadce82f3ed4c10962497c1 – NiKo 2012-10-14 12:44:49

回答

0

該表格可能不包含名稱爲'numero'的任何輸入或字段。確保有這個名字的輸入。

我試圖通過簡單地將垃圾變量添加到傳遞給填充方法的對象字面值來重現您的問題。我得到了完全相同的錯誤。