Javascript CasperJS无法使用fill()方法登录
我是Casper JS的新手,我对登录站点的Javascript CasperJS无法使用fill()方法登录,javascript,forms,login,fill,casperjs,Javascript,Forms,Login,Fill,Casperjs,我是Casper JS的新手,我对登录站点的fill()方法有问题。 在调试输出中,我到达登录页的url,该url应该在我登录后到达。但是,它会将我发送到一个空白页并断开: [debug] [phantom] Navigation requested: url=about:blank, type=Other, lock=true, isMainFrame=false 我已经测试了下面的代码以登录facebook,并且成功了。我还使用下面Casperjs代码的Phantomjs版本成功登录到下面
fill()
方法有问题。
在调试输出中,我到达登录页的url,该url应该在我登录后到达。但是,它会将我发送到一个空白页并断开:
[debug] [phantom] Navigation requested: url=about:blank, type=Other, lock=true, isMainFrame=false
我已经测试了下面的代码以登录facebook,并且成功了。我还使用下面Casperjs代码的Phantomjs版本成功登录到下面示例中的站点。因此,这个问题似乎与使用Casperjs fill()方法登录有关
1) 以下是html(出于安全目的,我将其设置为匿名):
3) 以下是控制台输出(我隐藏了URL):
感谢您的帮助。谢谢 尝试以下操作:
casper.start(start_url, function() {
this.waitForSelector('form#***id_form***', function() {
this.fill('form#***id_form***', {
'IDToken1': '***MY_ID***',
'IDToken2': '***MY_PASSWORD***'
}, true);
}
});
casper.then(function() {
...
}
很难说里面所有的审查员都在干什么。如果您不喜欢共享URL或ID,请将它们更改为有意义的一致性,否则就无法解决此类问题。
var start_url = 'https://***login_url***'
casper.start(start_url, function() {
this.test.assertExists('form#***id_form***', 'form is found');
this.fill('form#***id_form***', {
'IDToken1': '***MY_ID***',
'IDToken2': '***MY_PASSWORD***'
}, true);
});
casper.run();
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://***login_url***, HTTP GET
[debug] [phantom] Navigation requested: url=https://***url***, type=Other, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://***url***, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://***url***"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 https://***url*** (HTTP 302)
PASS form is found
[info] [remote] attempting to fetch form element from selector: 'form#***id_form***'
[debug] [remote] Set "IDToken1" field value to ***My_ID***
[debug] [remote] Set "IDToken2" field value to ***My_PASSWORD***
[info] [remote] submitting form to https://***login_link***, HTTP POST
[info] [phantom] Step 2/2: done in 1211ms.
[debug] [phantom] Navigation requested: url=https://***login_link***, type=FormSubmitted, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://***url***, type=FormSubmitted, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=http://***url***, type=FormSubmitted, lock=true, isMainFrame=true
[debug] [phantom] url changed to "http://***url***"
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] Navigation requested: url=https://***url***, type=Other, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://***url***, type=Other, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://***landing_page***, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://***landing_page***"
[debug] [phantom] Navigation requested: url=https://***url***, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=about:blank, type=Other, lock=true, isMainFrame=false
casper.start(start_url, function() {
this.waitForSelector('form#***id_form***', function() {
this.fill('form#***id_form***', {
'IDToken1': '***MY_ID***',
'IDToken2': '***MY_PASSWORD***'
}, true);
}
});
casper.then(function() {
...
}