且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用casperjs提交表单

更新时间:2023-02-15 14:40:36

该站点似乎是一个单页应用程序。 casperjs无法承担提交按钮的页面加载。您需要手动等待下一页加载。我使用了一个选择器,您可以在购物车页面上找到该选择器,但不能在产品页面上找到: .filled-cart

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

另一个问题是fill方法没有触发表单提交。您需要手动单击它。我也删除了隐藏字段的填充,因为这没有意义。

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 now
    this.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
});