CasperJS无法使用fill()方法登录

我是Casper JS的新手,我遇到了使用fill()方法登录网站的问题。 在调试输出中,我登录后应该到达着陆页的url。然而,然后送我到一个空白页,并打破:CasperJS无法使用fill()方法登录

[debug] [phantom] Navigation requested: url=about:blank, type=Other, lock=true, isMainFrame=false 

我已经测试下面的代码登录到Facebook和它的工作。我还在下面的例子中使用Phantomjs版本的Casperjs代码成功登录了该网站。所以这个问题似乎特定于使用Casperjs fill()方法登录。

1)下面是HTML(我把它匿名为安全起见):

//login form 

<form id="***id_form***" class="loginBox" method="post" action="https://***login_link***/">

// input login

<input id="IDToken1" type="text" value="" name="IDToken1">

// input password

<input id="IDToken2" type="password" name="IDToken2">

2)这是我的Casperjs代码:

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();

3)这里是控制台输出(我隐藏了网址):

[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() {

...

}

以上是 CasperJS无法使用fill()方法登录 的全部内容, 来源链接: utcz.com/qa/265127.html

回到顶部