6

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?

wim
  • 338,267
  • 99
  • 616
  • 750
pooh
  • 97
  • 2
  • 3
  • 8

3 Answers3

6

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:

  1. nameValuePair - name and value of the cookie in a format "name=value"

  2. 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

Community
  • 1
  • 1
Aleksi Yrttiaho
  • 8,266
  • 29
  • 36
1
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.
Manish Trivedi
  • 3,481
  • 5
  • 23
  • 29
1

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.

Zuabi
  • 1,112
  • 1
  • 13
  • 26