如何使用不带表单标签的CasperJS填写表单 [英] How to fill up form using CasperJS without form tag

查看:149
本文介绍了如何使用不带表单标签的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');

这篇关于如何使用不带表单标签的CasperJS填写表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆