selenium.driver.cookies
Cookie model and the per-session cookie store.
Cookie
struct Cookie;
A single WebDriver cookie.
name
string name;
The cookie name.
value
string value;
The cookie value.
path
string path;
The path the cookie is valid for, defaulting to "/" when serialized.
domain
string domain;
The domain the cookie is valid for, omitted from output when empty.
secure
bool secure;
Whether the cookie is restricted to secure transports.
httpOnly
bool httpOnly;
Whether the cookie is inaccessible to client-side scripts.
expiry
uint expiry;
Unix expiry time in seconds, omitted from output when zero.
sameSite
string sameSite;
SameSite policy, omitted from output when empty.
toJSON
JSONValue toJSON() const;
Serializes the cookie, omitting optional fields that are unset.
fromJSON
static Cookie fromJSON(JSONValue json);
Parses a cookie from a WebDriver cookie object.
name and value are required. Optional fields that are absent keep
their defaults: empty strings, zero for expiry, and false for
secure and httpOnly.
Parameters:
| Name | Description |
|---|---|
JSONValue json |
The cookie object returned by the driver. |
Returns: The parsed cookie.
Throws: JSONException if json is not an object, a required field is absent or
mistyped, or a present optional field has the wrong type.
ConvException if expiry cannot be represented as a uint.
CookieStore
struct CookieStore;
Cookie operations scoped to a single driver session.
This store is intentionally decoupled from Driver and reached through the
cookies UFCS helper rather than living on the driver itself.
all
Cookie[] all();
Every cookie visible to the current document.
find
Cookie find(string name);
Reads a single cookie by name.
Parameters:
| Name | Description |
|---|---|
string name |
The cookie name. |
Returns: The matching cookie.
Throws: InvalidArgumentException if the name is empty. NoSuchCookieException if no cookie matches.
add
void add(Cookie cookie);
Adds or updates a cookie on the current document.
Parameters:
| Name | Description |
|---|---|
Cookie cookie |
The cookie to set. |
Throws: UnableToSetCookieException if the browser rejects the cookie.
remove
void remove(string name);
Deletes a single cookie by name.
Parameters:
| Name | Description |
|---|---|
string name |
The cookie name. |
Throws: InvalidArgumentException if the name is empty.
clear
void clear();
Deletes every cookie for the current document.
cookies
CookieStore cookies(Driver driver);
Opens the cookie store for a session, used as driver.cookies.