0

I have a piece of PhantomJS code and I want to refactor it and move to CasperJS. However, in my original PhantomJS code, I have some lines of code directly operate on the page object and I'm not sure how to translate them to CasperJS. Below is part of my original code.

var cookies = "C_B_A=2; tips=1;";
var page = require("webpage").create();
page.settings.userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36";
cookies.split(";").forEach(function(pair){
    pair = pair.split("=");
    phantom.addCookie({
        "name": pair[0],
        "value": pair[1],
        "domain": ".mydomain.com"
    });
});

I searched CasperJS documentation and there seems no cookie related methods. Here my question is, is there any way for me to reference the underling PhantomJS page object and set its attributes?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Just a learner
  • 26,690
  • 50
  • 155
  • 234

1 Answers1

1

Yes, you can access it with casper.page or this.page inside of casper closures, but most of the time there is no need, because CasperJS provides better alternatives for PhantomJS functions.

The phantom object is also just there in CasperJS (regardless whether you use SlimerJS or PhantomJS as the underlying engine).

Artjom B.
  • 61,146
  • 24
  • 125
  • 222