如何使用不带表单标签的CasperJS填写表单

如何使用不带表单标签的CasperJS填写表单

问题描述:

我是CasperJS的新手,登录此网站时遇到问题 http:// weibo。 com / login.php

I'm new to CasperJS and I'm having problems in logging in into this site http://weibo.com/login.php

这是我尝试过的内容

this.fill('form#contact-form', {
    'username':    'test@test.com',
    'password':    'anypassword',

}, true);

我无法使用它,因为它没有格式。

I can't used that since it has no form.

所以我尝试了使用sendKeys的另一种方法。

so I tried a different method using sendKeys.

this.sendKeys('.W_input ', 'tinkerbell@gmail.com');

现在我的问题是输入文本中没有ID,只有CLASS,并且两者都用户名和密码具有相同的CLASS。我如何仅使用该类在文本框中键入内容?还是可以通过XPath使用sendKeys?

Now my problem in here is that the input text has no ID in it, only a CLASS and both username and password have the same CLASS in it. how can i type into that textbox using only that class? or is it possible to use sendKeys using XPath?

casper支持CSS3选择器( tuts +在您应记住的前30名中占了相当的比例),因此您可以执行以下操作:

casper supports CSS3 selectors (tuts+ has a decent rundown of the top 30 you should memorize) so you could do something like:

this.sendKeys('input [name = username]','tinkerbell@gmail.com');