Class: Selenium::WebDriver::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/common/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(bridge) ⇒ Options

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Options.



9
10
11
# File 'lib/selenium/webdriver/common/options.rb', line 9

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

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.delete(:expires)
    opts[:expiry] = seconds_from(obj)
  end


  @bridge.addCookie opts
end

#all_cookiesArray<Hash>

Get all cookies

Returns:

  • (Array<Hash>)

    list of cookies



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/selenium/webdriver/common/options.rb', line 76

def all_cookies
  @bridge.getAllCookies.map do |cookie|
    {
      :name    => cookie["name"],
      :value   => cookie["value"],
      :path    => cookie["path"],
      :domain  => cookie["domain"] && strip_port(cookie["domain"]),
      :expires => cookie["expiry"] && datetime_at(cookie['expiry']),
      :secure  => cookie["secure"]
    }
  end
end

Get the cookie with the given name

Parameters:

  • name (String)

    the name of the cookie

Returns:

  • (Hash, nil)

    the cookie, or nil if it wasn’t found.



48
49
50
# File 'lib/selenium/webdriver/common/options.rb', line 48

def cookie_named(name)
  all_cookies.find { |c| c[:name] == name }
end

#delete_all_cookiesObject

Delete all cookies



66
67
68
# File 'lib/selenium/webdriver/common/options.rb', line 66

def delete_all_cookies
  @bridge.deleteAllCookies
end

Delete the cookie with the given name

Parameters:

  • name (String)

    the name of the cookie to delete



58
59
60
# File 'lib/selenium/webdriver/common/options.rb', line 58

def delete_cookie(name)
  @bridge.deleteCookie name
end

#logsObject



97
98
99
# File 'lib/selenium/webdriver/common/options.rb', line 97

def logs
  @logs ||= Logs.new(@bridge)
end

#timeoutsObject



89
90
91
# File 'lib/selenium/webdriver/common/options.rb', line 89

def timeouts
  @timeouts ||= Timeouts.new(@bridge)
end

#windowObject



105
106
107
# File 'lib/selenium/webdriver/common/options.rb', line 105

def window
  @window ||= Window.new(@bridge)
end