문제

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();
도움이 되었습니까?

해결책

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);

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top