How to fill up form using CasperJS without form tag

Alex Strauss picture Alex Strauss · Oct 18, 2013 · Viewed 7.3k times · Source

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

here's what I've tried

this.fill('form#contact-form', {
    'username':    '[email protected]',
    'password':    'anypassword',

}, true);

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

so I tried a different method using sendKeys.

this.sendKeys('.W_input ', '[email protected]');

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?

Answer

hackerhasid picture hackerhasid · Apr 25, 2014

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]', '[email protected]');