Table of Contents

Class Cookie

Namespace
OpenQA.Selenium
Assembly
WebDriver.dll

Represents a cookie in the browser.

[Serializable]
public class Cookie
Inheritance
Cookie
Derived
Inherited Members

Constructors

Initializes a new instance of the Cookie class with a specific name and value.

public Cookie(string name, string value)

Parameters

name string

The name of the cookie.

value string

The value of the cookie.

Exceptions

ArgumentException

If the name is null or an empty string, or if it contains a semi-colon.

ArgumentNullException

If the value is null.

Initializes a new instance of the Cookie class with a specific name, value, and path.

public Cookie(string name, string value, string path)

Parameters

name string

The name of the cookie.

value string

The value of the cookie.

path string

The path of the cookie.

Exceptions

ArgumentException

If the name is null or an empty string, or if it contains a semi-colon.

ArgumentNullException

If the value is null.

Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.

public Cookie(string name, string value, string path, DateTime? expiry)

Parameters

name string

The name of the cookie.

value string

The value of the cookie.

path string

The path of the cookie.

expiry DateTime?

The expiration date of the cookie.

Exceptions

ArgumentException

If the name is null or an empty string, or if it contains a semi-colon.

ArgumentNullException

If the value is null.

Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.

public Cookie(string name, string value, string domain, string path, DateTime? expiry)

Parameters

name string

The name of the cookie.

value string

The value of the cookie.

domain string

The domain of the cookie.

path string

The path of the cookie.

expiry DateTime?

The expiration date of the cookie.

Exceptions

ArgumentException

If the name is null or an empty string, or if it contains a semi-colon.

ArgumentNullException

If the value is null.

Initializes a new instance of the ReturnedCookie class with a specific name, value, domain, path and expiration date.

public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite)

Parameters

name string

The name of the cookie.

value string

The value of the cookie.

domain string

The domain of the cookie.

path string

The path of the cookie.

expiry DateTime?

The expiration date of the cookie.

secure bool

true if the cookie is secure; otherwise false

isHttpOnly bool

true if the cookie is an HTTP-only cookie; otherwise false

sameSite string

The SameSite value of cookie.

Exceptions

ArgumentException

If the name and value are both an empty string, if the name contains a semi-colon, or if same site value is not valid.

ArgumentNullException

If the name, value or currentUrl is null.

Properties

Gets the domain of the cookie.

[JsonPropertyName("domain")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Domain { get; }

Property Value

string

Gets the expiration date of the cookie.

[JsonIgnore]
public DateTime? Expiry { get; }

Property Value

DateTime?

Gets a value indicating whether the cookie is an HTTP-only cookie.

[JsonPropertyName("httpOnly")]
public virtual bool IsHttpOnly { get; }

Property Value

bool

Gets the name of the cookie.

[JsonPropertyName("name")]
public string Name { get; }

Property Value

string

Gets the path of the cookie.

[JsonPropertyName("path")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public virtual string Path { get; }

Property Value

string

Gets the SameSite setting for the cookie.

[JsonPropertyName("sameSite")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public virtual string SameSite { get; }

Property Value

string

Gets a value indicating whether the cookie is secure.

[JsonPropertyName("secure")]
public virtual bool Secure { get; }

Property Value

bool

Gets the value of the cookie.

[JsonPropertyName("value")]
public string Value { get; }

Property Value

string

Methods

Determines whether the specified Object is equal to the current Object.

public override bool Equals(object obj)

Parameters

obj object

The Object to compare with the current Object.

Returns

bool

true if the specified Object is equal to the current Object; otherwise, false.

Converts a Dictionary to a Cookie.

public static Cookie FromDictionary(Dictionary<string, object> rawCookie)

Parameters

rawCookie Dictionary<string, object>

The Dictionary object containing the cookie parameters.

Returns

Cookie

A Cookie object with the proper parameters set.

Serves as a hash function for a particular type.

public override int GetHashCode()

Returns

int

A hash code for the current Object.

Creates and returns a string representation of the cookie.

public override string ToString()

Returns

string

A string representation of the cookie.