CasperJS / PhantomJS, how to keep the old page open?

I have a form with some dynamic input that needs to be filled out. The problem is that to fill out the form I need to visit another page to get data that depends on the input on the previous page. Therefore, after I received the data and then added it to the form, the form has already been changed, so I need to keep this form open while I receive the data for it. The question is how to do this?

+3
source share
2 answers

Maybe with casper.back () and casper.forward (): https://github.com/n1k0/casperjs/blob/master/tests/suites/casper/history.js I believe that the previous form will be saved on the previous step. Hope try this.

Edit: getData (newPage) was an example of your own method, you can try something like this:

var password ="wtoc95a";

casper.getData = function (newPage, previousPageInputData) {
    //visit another page
    casper.open(newPage)
    //or casper.open(newPage+previousPageInputData) if the new page opened use the previous input
    .then(function() {
            //here you do what you want using "input" argument of the previous page
            //just return the data you need to fill the form
    });
    return dataNeeded;
};

And in your form : 
this.fill('form[id="signup_frm"]', { 
                nick_name: "pseudo", 
                e_mail: "mail",
                password: "password",
                password2: password,
                input : casper.getData(arg1,arg2)

http://docs.casperjs.org/en/1.1-beta2/extending.html

0
source

Perhaps you can create two instances of casper. If your first copy will have the first page, and if necessary, create another copy and get data from it. Store data globally in a cache.

Do a waitFor until your variable value is set to the first instance.

0
source

All Articles