2012-07-09 64 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'的任何输入或字段。确保有这个名字的输入。

我试图通过简单地将垃圾变量添加到传递给填充方法的对象字面值来重现您的问题。我得到了完全相同的错误。