提交下一个加载页面的表单命令后,不会在CasperJS中执行

时间:2015-05-13 03:09:35

标签: javascript casperjs

提交表单后,我想填写并提交第二张表单,但第二次.then()无效,请参阅以下代码:

情况正在点击“添加新公司”按钮我收到一个表单,提交后我重定向到另一个表单,我在另一个then()编写脚本但是它不能在这里工作

var casper = require('casper').create(); var config = {
  url: "http://www.example.com",
};
config.form = {
  "subForm_Company_Info[name]": "testCompany",
  "subForm_Company_Info[company_marketing_email]": "me@example.com",
  "subForm_Company_Info[company_industry]":"1",
  "subForm_Company_Info[decision_maker_first_name]":"Asd",
  "subForm_Company_Info[decision_maker_last_name]":"Asd",
  "subForm_Company_Info[decision_maker_email]":"Asd@gmail.com",
  "subForm_Company_Info[decision_maker_phone]":"1122223333"
};
config.marketInfo = {
  "subForm_Company_Info[information_6]": "test",
  "subForm_Company_Info[information_7]": "test",
  "subForm_Company_Info[information_8]": "test",
  "subForm_Company_Info[information_1]": "test",
  "subForm_Company_Info[information_2]": "test",
  "subForm_Company_Info[information_3]": "test",
  "subForm_Company_Info[information_4]": "test",
  "subForm_Company_Info[information_5]": "test"
};
casper.test.begin('Testing navigation and forms', 10, function suite(test) {
    casper.start(config.url,function(){

        this.click('li.right a');
        test.comment('Clicking the Add new company link...');

    })
    .viewport(1360,725);

    casper.then(function(){
        test.comment('open url');
        casper.fill('#submitchanges', config.form, false);
        this.click("button#same");
        this.click("button.submitchanges");
        test.comment('submit form....');
    });

    // its second form which doesn't get execute, execution stops from here, provide the solution

    casper.then(function() {
        test.comment('ENTER*****');
        casper.fill('div#market-information form', config.marketInfo, true);
        test.comment('fill form---..');
    });

    casper.run(function() {
        test.done();
    });

});

0 个答案:

没有答案