casper.start page with cookies.txt

933 views
Skip to first unread message

steven h

unread,
Aug 1, 2013, 12:03:22 PM8/1/13
to casp...@googlegroups.com
i have a web app that supports multiple languages, and all i want to do is load the page with a language cookie set and take a screenshot. 

var casper = require('casper').create();
var cookieFileName = 'cookies.txt';

// grab cookies from file 
var fs = require('fs');
var utils = require('utils');
phantom.cookies = fs.read(cookieFileName);

casper.start('https://local.dev', function() {
  this.capture('cookietest.png', { top: 0, left:0, width:1000, height:  4000});  
});

casper.run();

it doesn't seem to be loading the cookie? is there an easier way to do this? (i COULD just have casper click through the links to actually set the language in the browser, but i would prefer to do it programatically)

Robert Igl

unread,
Aug 1, 2013, 12:25:07 PM8/1/13
to casp...@googlegroups.com
Try to call the cookie when you start your script, also you maybe need to turn web-security off ;)
This link may help you

steven h

unread,
Aug 1, 2013, 12:27:50 PM8/1/13
to casp...@googlegroups.com
Thanks Robert! i believe that the --cookies-file=/tmp/mycookies.txt   parameter actually *saves* the cookie to that file, instead of loading it...?

Robert Igl

unread,
Aug 1, 2013, 1:23:09 PM8/1/13
to casp...@googlegroups.com
Look at the PhantomJS-API, it defines the file where the cookies are saved, so you could also give a file in which a cookie already exists ;)
To add a cookie to this file just use .addCookie
Reply all
Reply to author
Forward
0 new messages