I want to create a cookie using selenium. I have seen a method which supports this like selenium.createcookie(arg1,arg0)
, but I'm a bit confused about the arguments passed. Can anyone please give me an example?
3 Answers
createCookie ( nameValuePair,optionsString ) Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.
Arguments:
nameValuePair - name and value of the cookie in a format "name=value"
optionsString - options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.
source: Selenium reference

- 1
- 1

- 8,266
- 29
- 36
-
Can we give the cookie domain in any of the argument? Coz that cookie should get added to some xyz domain.Please help – pooh Feb 18 '11 at 05:56
-
I guess you can set the domain= attribute as one of the options in optionsString argument. – Aleksi Yrttiaho Feb 18 '11 at 06:04
createCookie ( nameValuePair,optionsString )
Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.
Arguments:
nameValuePair - name and value of the cookie in a format "name=value"
optionsString - options for the cookie. Currently supported options include 'path' and 'max_age'. the optionsString's format is "path=/path/, max_age=60". The order of options are irrelevant, the unit of the value of 'max_age' is second.

- 3,481
- 5
- 23
- 29
-
http://www.cloudtesting.com/blog/2009/08/24/howto-cookie-manipulation-with-selenium-and-cloud-testing/ – Manish Trivedi Feb 18 '11 at 05:38
Go on a site of your choice (that does create cookies) using firefox and go to Edit>Preferences>Privacy>Remove Individual Cookies. Click on one of the cookies. This will give you an idea of how to use the createCookie call. I switched the term of the option Domain the term by Host, which worked fine.

- 1,112
- 1
- 13
- 26