Class: Selenium::WebDriver::Options

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

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ Options

Returns a new instance of Options.



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

def initialize(driver)
  @bridge = driver.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

Raises:

  • (ArgumentError)

    if :name or :value is not specified



25
26
27
28
29
30
31
32
33
# File 'lib/selenium/webdriver/options.rb', line 25

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

  @bridge.addCookie opts
end

#all_cookiesArray<Hash>

Get all cookies

Returns:

  • (Array<Hash>)

    list of cookies



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/selenium/webdriver/options.rb', line 59

def all_cookies
  @bridge.getAllCookies.map do |cookie|
    {
      :name    => cookie["name"],
      :value   => cookie["value"],
      :path    => cookie["path"],
      :domain  => cookie["domain"],
      :expires => cookie["expires"],
      :secure  => cookie["secure"]
    }
  end
end

#delete_all_cookiesObject

Delete all cookies



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

def delete_all_cookies
  @bridge.deleteAllCookies
end

Delete the cookie with the given name

Parameters:

  • name (String)

    the name of the cookie to delete



41
42
43
# File 'lib/selenium/webdriver/options.rb', line 41

def delete_cookie(name)
  @bridge.deleteCookie name
end

#speedObject



72
73
74
# File 'lib/selenium/webdriver/options.rb', line 72

def speed
  @bridge.getSpeed.downcase.to_sym
end

#speed=(speed) ⇒ Object



76
77
78
# File 'lib/selenium/webdriver/options.rb', line 76

def speed=(speed)
  @bridge.setSpeed(speed.to_s.upcase)
end

#timeoutsObject



80
81
82
# File 'lib/selenium/webdriver/options.rb', line 80

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