Method: Selenium::WebDriver::Options#add_cookie

Defined in:
lib/selenium/webdriver/common/options.rb

Add a cookie to the browser

Parameters:

  • opts (Hash) (defaults to: {})

    the options to create a cookie with.

Options Hash (opts):

  • :name (String)

    A name

  • :value (String)

    A value

  • :path (String) — default: '/'

    A path

  • :secure (String) — default: false

    A boolean

  • :expires (Time, DateTime, Numeric, nil) — default: nil

    Expiry date, either as a Time, DateTime, or seconds since epoch.

Raises:

  • (ArgumentError)

    if :name or :value is not specified


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/selenium/webdriver/common/options.rb', line 26

def add_cookie(opts = {})
  raise ArgumentError, "name is required" unless opts[:name]
  raise ArgumentError, "value is required" unless opts[:value]

  opts[:path] ||= "/"
  opts[:secure] ||= false

  if obj = opts[:expires]
    opts[:expiry] = seconds_from(obj)
  end


  @bridge.addCookie opts
end