Unable to fill the login credentials from commandline in casperjs

167 views Asked by At

I am new to casperjs and I am trying to login to our corporate website. This is what I am running on my command line:

casperjs someJob.js --username=My_Username --password=My_Password

My code is as follows:

var LOGIN_USERNAME, LOGIN_PASSWORD, casp;

casp = require('casper').create({
    clientScripts: ['jquery.min.js'],
     debugLevel: "debug",
     viewportSize: {
          width: 1024,
          height: 768
     },
     verbose: true,
     logLevel: 'info'
});

LOGIN_USERNAME = casp.cli.get('username');
LOGIN_PASSWORD = casp.cli.get('password');

casp.echo('Checking Username and password');
casp.echo(LOGIN_USERNAME);

casp.start('mywebsite.com', function () {

     casp.fill('form', {
          'username': LOGIN_USERNAME,
          'password': LOGIN_PASSWORD
     }, true );

     });

casp.run();

I am unable to login to the website and I am seeing the following on the screen after which nothing happens: [info] [remote] attempting to fetch form element from selector: 'form'

Any help is appreciated. Thank you.

1

There are 1 answers

0
Jonatas Walker On

You have to use a CSS selector to your form:

 casp.fill('form#form-id', {
      'username': LOGIN_USERNAME,
      'password': LOGIN_PASSWORD
 }, true );