使用casperjs提交表单 [英] Submitting a form with casperjs

查看:75
本文介绍了使用casperjs提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表格使用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
    this.fill('form#add-to-cart-form', {
        'options[416]': '2884',
        'productId': '1093'
    }, true);
});

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

这里的问题是相同的 URL 被程序记录,而如果您打开页面并提交,它将转到< a href = http://m.kamajewellery.com/shop/checkout/cart?context=item_already_in_cart rel = nofollow>结帐页面。

The problem here is that the same URL is getting logged by the program, whereas if you open the page and submit it, it goes to the checkout page.

任何提示出了什么问题?

Any clue what is going wrong?

推荐答案

该站点似乎是一个单页应用程序。 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
});

这篇关于使用casperjs提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆