Question

I have got a form that I am trying to fill using CasperJS. The code itself doesn't appear to have any problems (no errors being returned) - but I seem unable to 'check' that the form has been filled out.

When I dump the 'first_name' it appears to be blank - even though I have set this to be filled with the string 'Joe' - any ideas what I am doing wrong?

casper.start(url);
casper.then(function() {
    this.fill('form[name="phones_display"]', {
        'first_name'            : 'Joe', // Required
        'last_name'             : 'bloggs', // Required
        'check_payable'         : '', // name to cheque if different from your name
        'payment_method'        : 'check', // Required check, paypal
        'shipping_method'       : '', // envelope, fedex
        'email_address'         : 'joe@bloggs.com', // Required
        'paypal_email_address'  : '',
        'telephone_number'      : '12345678', // Required
        'street_address_1'      : '', // Required
        'street_address_2'      : '',
        'city'                  : '', // Required
        'state'                 : '',
        'zip_code'              : '', // Required
        'hear'                  : '',
        'otherreason'           : ''
    }, true);
});

casper.then(function() {
    var first_name = this.evaluate(function() {
        return $('input[name="first_name"]').val();
    });

    require('utils').dump(first_name);
});
casper.run();
Was it helpful?

Solution

It happens because after fill the form, it is submitted. so when you try to get the input 'the first name', the form has been cleaned. In order to avoid this, just change the third parameter of casper.fill() method to false.

fill(String selector, Object values[, Boolean submit])

Example:

this.fill('form[name="phones_display"]', {
    'first_name'            : 'Joe', // Required
    'last_name'             : 'bloggs', // Required
     .... 
}, false);

OTHER TIPS

Figured it out... the page has messed up form tags so my code was never going to work :-(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top