There are several ways, but the easiest way is to use page.addCookie or phantom.addCookie that PhantomJS provides, but you will need to set the domain (and path). Keep in mind that page.addCookie must be executed on the loaded page, whereas phantom.addCookie may be executed earlier.
var cookie = "someCookieName=Value; otherName=Value"; var domain = "example.com"; cookie.split(";").forEach(function(pair){ pair = pair.split("="); phantom.addCookie({ 'name': pair[0], 'value': pair[1], 'domain': domain }); }); casper.start("http://example.com", function(){
source share