Skip to content Skip to sidebar Skip to footer

Submitting A Form With Casperjs

I have a simple form to submit using casperjs. For the same, I have the following version of the code - casper.then(function() { // fill the dropdown and click on buy now t

Solution 1:

The site seems to be a single page application. The page load of the submit button isn't picked up by casperjs. You need to manually wait for the next page to load. I used a selector that you can find on the cart page but not on the product page: .filled-cart

The other problem was that the fill method didn't trigger the form submit. You need to manually click it. Also I removed the fill for the hidden field, as it doesn't make sense.

casper.then(function() {
    // fill the dropdown and click on buy nowthis.fill('form#add-to-cart-form', {
        'options[416]': '2884'
    });
    this.click("button[type=submit]");
});

casper.waitForSelector(".filled-cart");

casper.then(function() {
    console.log("Checkout URL: ", this.getCurrentUrl()); // not going correctly
});

Post a Comment for "Submitting A Form With Casperjs"