Currently Browsing

Posts Tagged ‘ deleting cookies ’

Cookie manipulation in webdriver sessions

Manipulating cookies in selenium Webdriver sessions is really easy, it can enhance your testing and you can make more detailed logs and pinpointing issues.
To be able to insert a cookie you have to have a Webdriver instance at hand, you have to create a Webdriver cookie add it to your Webdriver instance.
To create a cookie you can use on of the constructors of the org.openqa.selenium.Cookie class:

Cookie(java.lang.String name, java.lang.String value)

Create a cookie for the default path with the given name and value with no expiry set.

Cookie(java.lang.String name, java.lang.String value, java.lang.String path)

Create a cookie with the given name value and path.

Cookie(java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expiry)

Creates an insecure non-httpOnly cookie with no domain specified.