Casperjs:我如何提交一个有action =“#”的表单

时间:2014-01-01 15:00:38

标签: javascript forms casperjs

我想让我的casper登录网站,但它有这样的形式:

<form action="#" method="POST" name="logon" id="loginForm" onsubmit="DoLogin(); return false;">

我在我的casper中得到了这个

[info] [remote] attempting to fetch form element from selector: 'div.mainLoginLe
ftPanel form'
[debug] [remote] Set "username" field value to foo
[debug] [remote] Set "password" field value to ***
[info] [remote] submitting form to #, HTTP POST
[warning] [remote] unable to submit form

如何触发“DoLogin();”或以不同的方式提交表单?

1 个答案:

答案 0 :(得分:3)

只需运行该功能。 Casper在网站的背景下运行。

casper.fill('#loginForm', {/* stuff */}, false);//Note the false at the end to not submit it.

casper.evaluate(function() {
    DoLogin();
});