2015-06-21 114 views
0

我正在使用此代码登录窗体。我得到错误。casperjs登录表单错误

var casper = require('casper').create(); 

var url = "www.example.com"; 


casper.start(url,function(){ 
    this.echo(this.getTitle()); 
}); 

casper.waitForResource(url,function() { 
    this.fillSelectors("form[method='post']", { 
     'input[name="userName"]' : 'usr1', 
     'input[name="password"]': 'pswed1' 
    }, true); 
}); 

casper.run(); 

http://prntscr.com/7jkia1

我几乎复制的例子,我在栈上找到,但我仍然得到错误...怎样做才能解决这个问题?

+0

它告诉你它找不到形式... – mfreitas

+0

我得到了,但我试过一遍又一遍......没有理由...... – macroscripts

+0

你确定你是正确的网页上?你有截图检查('casper.capture()')?请注册到'resource.error','page.error','remote.message'和'casper.page.onResourceTimeout'事件([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf)) 。也许有错误。 –

回答

0

似乎casper不能为form [method ='post'](使用fillSelectors)做一个选择器,它也不适合我。但是,如果你指定任何其他属性,如名称,ID,类,enctype,动作等,它的作品。

var casper = require('casper').create(); 

var url = "https://careershub.bbc.co.uk/members/"; 

casper.start(url,function(){ 
    this.echo(this.getTitle()); 
}); 

casper.waitForResource(url,function() { 
    this.fillSelectors('form#registration-form', { 
     'input[name="name_first"]' : 'firstname', 
     'input[name="name_last"]': 'lastname' 
    }, true); 

    this.captureSelector('test.png', 'form'); 
}); 

casper.run(); 
+0

我试过这段代码,并得到了错误。 http://prntscr.com/7jl8x5 当我去了802线在casper.js文件我得到了这个。 http://prntscr.com/7jl9bb – macroscripts

+0

@macroscripts不知道你为什么得到这个错误,在这里完美地工作(http://i.imgur.com/gctDw1Q.png,这两个输入得到正确填写)。也许尝试重新安装casperjs和phantomjs。 – mfreitas

+1

@macroscripts我注意到你的控制台甚至没有打印出页面标题。你在代理或其他东西后面吗?似乎你甚至无法正确连接到网站。 – mfreitas