1

I have url, userName, pasword of a site. This site doesn't use form element. So the structure is like this.

Both username field has .user_name class while password field has #passwd id.

Moreover login button has #login id.

I know I can use jQuery with casperjs and able to inject it in the page.

I tried the following code inside

casper.thenEvaluate(function() {
    $(fe.u).val(user.uname);
});

but it doesn't work. What else I can try?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
arpit
  • 728
  • 7
  • 22
  • If it's an `input`, you may use `$(".user_name").val(user.uname)` – lshettyl Jul 17 '15 at 12:10
  • possible duplicate of [CasperJS passing variable to evaluate can't get it to work](http://stackoverflow.com/questions/22597987/casperjs-passing-variable-to-evaluate-cant-get-it-to-work), because `user.uname` is unknown inside `evaluate()`, you have to pass it in. – Artjom B. Jul 17 '15 at 12:11

1 Answers1

2

I don't think you need to use jQuery to fill the field and submit it. The sendKeys() function normally works well without forms:

casper.then( function() 
{
     casper.sendKeys('.user_name', 'kevin', {reset: true});
     casper.sendKeys('#passwd', 'sdkfmkds123', {reset: true});
});
casper.then( function() 
{
    casper.click('#login');
});
// Get/Echo the actual URL
casper.then( function() 
{
    casper.echo(casper.getCurrentUrl());
})

To get the URL, call casper.getCurrentUrl() afterwards. In the case above the URL is echoed after the login.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
dasmelch
  • 532
  • 3
  • 11