123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Remote::Bridge Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: rb/lib/selenium/webdriver/remote/bridge/commands.rb,
rb/lib/selenium/webdriver/remote/bridge.rb

Overview

Constant Summary

  • COMMANDS =
    # File 'rb/lib/selenium/webdriver/remote/bridge/commands.rb', line 29
    {
      status: [:get, 'status'],
    
      #
      # session handling
      #
    
      new_session: [:post, 'session'],
      delete_session: [:delete, 'session/:session_id'],
    
      #
      # basic driver
      #
    
      get: [:post, 'session/:session_id/url'],
      get_current_url: [:get, 'session/:session_id/url'],
      back: [:post, 'session/:session_id/back'],
      forward: [:post, 'session/:session_id/forward'],
      refresh: [:post, 'session/:session_id/refresh'],
      get_title: [:get, 'session/:session_id/title'],
    
      #
      # window and Frame handling
      #
    
      get_window_handle: [:get, 'session/:session_id/window'],
      new_window: [:post, 'session/:session_id/window/new'],
      close_window: [:delete, 'session/:session_id/window'],
      switch_to_window: [:post, 'session/:session_id/window'],
      get_window_handles: [:get, 'session/:session_id/window/handles'],
      fullscreen_window: [:post, 'session/:session_id/window/fullscreen'],
      minimize_window: [:post, 'session/:session_id/window/minimize'],
      maximize_window: [:post, 'session/:session_id/window/maximize'],
      set_window_rect: [:post, 'session/:session_id/window/rect'],
      get_window_rect: [:get, 'session/:session_id/window/rect'],
      switch_to_frame: [:post, 'session/:session_id/frame'],
      switch_to_parent_frame: [:post, 'session/:session_id/frame/parent'],
    
      #
      # element
      #
    
      find_element: [:post, 'session/:session_id/element'],
      find_elements: [:post, 'session/:session_id/elements'],
      find_child_element: [:post, 'session/:session_id/element/:id/element'],
      find_child_elements: [:post, 'session/:session_id/element/:id/elements'],
      find_shadow_child_element: [:post, 'session/:session_id/shadow/:id/element'],
      find_shadow_child_elements: [:post, 'session/:session_id/shadow/:id/elements'],
      get_active_element: [:get, 'session/:session_id/element/active'],
      get_element_shadow_root: [:get, 'session/:session_id/element/:id/shadow'],
      is_element_selected: [:get, 'session/:session_id/element/:id/selected'],
      get_element_attribute: [:get, 'session/:session_id/element/:id/attribute/:name'],
      get_element_property: [:get, 'session/:session_id/element/:id/property/:name'],
      get_element_css_value: [:get, 'session/:session_id/element/:id/css/:property_name'],
      get_element_aria_role: [:get, 'session/:session_id/element/:id/computedrole'],
      get_element_aria_label: [:get, 'session/:session_id/element/:id/computedlabel'],
      get_element_text: [:get, 'session/:session_id/element/:id/text'],
      get_element_tag_name: [:get, 'session/:session_id/element/:id/name'],
      get_element_rect: [:get, 'session/:session_id/element/:id/rect'],
      is_element_enabled: [:get, 'session/:session_id/element/:id/enabled'],
    
      #
      # document handling
      #
    
      get_page_source: [:get, 'session/:session_id/source'],
      execute_script: [:post, 'session/:session_id/execute/sync'],
      execute_async_script: [:post, 'session/:session_id/execute/async'],
    
      #
      # cookies
      #
    
      get_all_cookies: [:get, 'session/:session_id/cookie'],
      get_cookie: [:get, 'session/:session_id/cookie/:name'],
      add_cookie: [:post, 'session/:session_id/cookie'],
      delete_cookie: [:delete, 'session/:session_id/cookie/:name'],
      delete_all_cookies: [:delete, 'session/:session_id/cookie'],
    
      #
      # timeouts
      #
    
      get_timeouts: [:get, 'session/:session_id/timeouts'],
      set_timeout: [:post, 'session/:session_id/timeouts'],
    
      #
      # actions
      #
    
      actions: [:post, 'session/:session_id/actions'],
      release_actions: [:delete, 'session/:session_id/actions'],
      print_page: [:post, 'session/:session_id/print'],
    
      #
      # Element Operations
      #
    
      element_click: [:post, 'session/:session_id/element/:id/click'],
      element_clear: [:post, 'session/:session_id/element/:id/clear'],
      element_send_keys: [:post, 'session/:session_id/element/:id/value'],
    
      #
      # alerts
      #
    
      dismiss_alert: [:post, 'session/:session_id/alert/dismiss'],
      accept_alert: [:post, 'session/:session_id/alert/accept'],
      get_alert_text: [:get, 'session/:session_id/alert/text'],
      send_alert_text: [:post, 'session/:session_id/alert/text'],
    
      #
      # screenshot
      #
    
      take_screenshot: [:get, 'session/:session_id/screenshot'],
      take_element_screenshot: [:get, 'session/:session_id/element/:id/screenshot'],
    
      #
      # virtual-authenticator
      #
    
      add_virtual_authenticator: [:post, 'session/:session_id/webauthn/authenticator'],
      remove_virtual_authenticator: [:delete, 'session/:session_id/webauthn/authenticator/:authenticatorId'],
      add_credential: [:post, 'session/:session_id/webauthn/authenticator/:authenticatorId/credential'],
      get_credentials: [:get, 'session/:session_id/webauthn/authenticator/:authenticatorId/credentials'],
      remove_credential: [:delete,
                          'session/:session_id/webauthn/authenticator/:authenticatorId/credentials/:credentialId'],
      remove_all_credentials: [:delete, 'session/:session_id/webauthn/authenticator/:authenticatorId/credentials'],
      set_user_verified: [:post, 'session/:session_id/webauthn/authenticator/:authenticatorId/uv']
    
    }.freeze
  • ESCAPE_CSS_REGEXP =
    # File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 673
    /(['"\\#.:;,!?+<>=~*^$|%&@`{}\-\[\]()])/
  • PORT =
    # File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 27
    4444
  • QUIT_ERRORS =
    # File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 186
    [IOError].freeze
  • UNICODE_CODE_POINT =
    # File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 674
    30

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::Selenium::WebDriver::Atoms - Included

Constructor Details

.new(url:, http_client: nil) ⇒ Bridge

Initializes the bridge with the given server URL

Parameters:

  • url (String, URI)

    url for the remote server

  • http_client (Object)

    an HTTP client instance that implements the same protocol as Http::Default

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 39

def initialize(url:, http_client: nil)
  uri = url.is_a?(URI) ? url : URI.parse(url)
  uri.path += '/' unless uri.path.end_with?('/')

  @http = http_client || Http::Default.new
  @http.server_url = uri
  @file_detector = nil
end

Instance Attribute Details

#alert=(keys) (writeonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 123

def alert=(keys)
  execute :send_alert_text, {}, {value: keys.chars, text: keys}
end

#capabilities (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 30

attr_reader :capabilities

#file_detector (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 29

attr_accessor :http, :file_detector

#http (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 29

attr_accessor :http, :file_detector

#timeouts (rw)

timeouts

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 103

def timeouts
  execute :get_timeouts, {}
end

#timeouts=(timeouts) (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 107

def timeouts=(timeouts)
  execute :set_timeout, {}, timeouts
end

Instance Method Details

#accept_alert

alerts

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 115

def accept_alert
  execute :accept_alert
end

#action(async: false, devices: [], duration: 250) Also known as: #actions

actions

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 374

def action(async: false, devices: [], duration: 250)
  ActionBuilder.new self, async: async, devices: devices, duration: duration
end

#actions(async: false, devices: [], duration: 250)

Alias for #action.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 377

alias actions action

#active_element Also known as: #switch_to_active_element

finding elements

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 502

def active_element
  Element.new self, element_id_from(execute(:get_active_element))
end

#add_credential(credential, id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 562

def add_credential(credential, id)
  execute :add_credential, {authenticatorId: id}, credential
end

#add_virtual_authenticator(options)

virtual-authenticator

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 553

def add_virtual_authenticator(options)
  authenticator_id = execute :add_virtual_authenticator, {}, options.as_json
  VirtualAuthenticator.new(self, authenticator_id, options)
end

#alert_text

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 127

def alert_text
  execute :get_alert_text
end

#browser

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 84

def browser
  @browser ||= begin
    name = @capabilities.browser_name
    name ? name.tr(' -', '_').downcase.to_sym : 'unknown'
  end
end

#clear_element(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 401

def clear_element(element)
  execute :element_clear, id: element
end

#clear_local_storage

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 296

def clear_local_storage
  execute_script('localStorage.clear()')
end

#clear_session_storage

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 320

def clear_session_storage
  execute_script('sessionStorage.clear()')
end

#click_element(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 391

def click_element(element)
  execute :element_click, id: element
end

#close

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 195

def close
  execute :close_window
end

#command_list

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 582

def command_list
  COMMANDS
end

#commands(command) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 614

def commands(command)
  command_list[command]
end

#convert_locator(how, what) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 648

def convert_locator(how, what)
  how = SearchContext::FINDERS[how.to_sym] || how

  case how
  when 'class name'
    how = 'css selector'
    what = ".#{escape_css(what.to_s)}"
  when 'id'
    how = 'css selector'
    what = "##{escape_css(what.to_s)}"
  when 'name'
    how = 'css selector'
    what = "*[name='#{escape_css(what.to_s)}']"
  end

  if what.is_a?(Hash)
    what = what.each_with_object({}) do |(h, w), hash|
      h, w = convert_locator(h.to_s, w)
      hash[h] = w
    end
  end

  [how, what]
end

#cookies

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 362

def cookies
  execute :get_all_cookies
end

#create_session(capabilities)

Creates session.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 52

def create_session(capabilities)
  response = execute(:new_session, {}, prepare_capabilities_payload(capabilities))

  @session_id = response['sessionId']
  capabilities = response['capabilities']

  raise Error::WebDriverError, 'no sessionId in returned payload' unless @session_id

  @capabilities = Capabilities.json_create(capabilities)

  case @capabilities[:browser_name]
  when 'chrome', 'chrome-headless-shell'
    extend(WebDriver::Chrome::Features)
  when 'firefox'
    extend(WebDriver::Firefox::Features)
  when 'msedge', 'MicrosoftEdge'
    extend(WebDriver::Edge::Features)
  when 'Safari', 'Safari Technology Preview'
    extend(WebDriver::Safari::Features)
  when 'internet explorer'
    extend(WebDriver::IE::Features)
  end
end

#credentials(authenticator_id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 566

def credentials(authenticator_id)
  execute :get_credentials, {authenticatorId: authenticator_id}
end

#delete_all_cookies

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 366

def delete_all_cookies
  execute :delete_all_cookies
end

#dismiss_alert

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 119

def dismiss_alert
  execute :dismiss_alert
end

#element_aria_label(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 446

def element_aria_label(element)
  execute :get_element_aria_label, id: element
end

#element_aria_role(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 442

def element_aria_role(element)
  execute :get_element_aria_role, id: element
end

#element_attribute(element, name)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 429

def element_attribute(element, name)
  WebDriver.logger.debug "Using script for :getAttribute of #{name}", id: :script
  execute_atom :getAttribute, element, name
end

#element_displayed?(element) ⇒ Boolean

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 489

def element_displayed?(element)
  WebDriver.logger.debug 'Using script for :isDisplayed', id: :script
  execute_atom :isDisplayed, element
end

#element_dom_attribute(element, name)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 434

def element_dom_attribute(element, name)
  execute :get_element_attribute, id: element, name: name
end

#element_enabled?(element) ⇒ Boolean

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 481

def element_enabled?(element)
  execute :is_element_enabled, id: element
end

#element_id_from(id) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 635

def element_id_from(id)
  id['ELEMENT'] || id[Element::ELEMENT_KEY]
end

#element_location(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 458

def element_location(element)
  data = execute :get_element_rect, id: element

  Point.new data['x'], data['y']
end

#element_location_once_scrolled_into_view(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 470

def element_location_once_scrolled_into_view(element)
  send_keys_to_element(element, [''])
  element_location(element)
end

#element_property(element, name)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 438

def element_property(element, name)
  execute :get_element_property, id: element, name: name
end

#element_rect(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 464

def element_rect(element)
  data = execute :get_element_rect, id: element

  Rectangle.new data['x'], data['y'], data['width'], data['height']
end

#element_screenshot(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 272

def element_screenshot(element)
  execute :take_element_screenshot, id: element
end

#element_selected?(element) ⇒ Boolean

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 485

def element_selected?(element)
  execute :is_element_selected, id: element
end

#element_size(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 475

def element_size(element)
  data = execute :get_element_rect, id: element

  Dimension.new data['width'], data['height']
end

#element_tag_name(element)

element properties

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 425

def element_tag_name(element)
  execute :get_element_tag_name, id: element
end

#element_text(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 454

def element_text(element)
  execute :get_element_text, id: element
end

#element_value(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 450

def element_value(element)
  element_property element, 'value'
end

#element_value_of_css_property(element, prop)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 494

def element_value_of_css_property(element, prop)
  execute :get_element_css_value, id: element, property_name: prop
end

#escape_css(string) (private)

Escapes invalid characters in CSS selector.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 678

def escape_css(string)
  string = string.gsub(ESCAPE_CSS_REGEXP) { |match| "\\#{match}" }
  string = "\\#{UNICODE_CODE_POINT + Integer(string[0])} #{string[1..]}" if string[0]&.match?(/[[:digit:]]/)

  string
end

#escaper (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 610

def escaper
  @escaper ||= defined?(URI::Parser) ? URI::DEFAULT_PARSER : URI
end

#execute(command, opts = {}, command_hash = nil) ⇒ WebDriver::Remote::Response (private)

executes a command on the remote server.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 594

def execute(command, opts = {}, command_hash = nil)
  verb, path = commands(command) || raise(ArgumentError, "unknown command: #{command.inspect}")
  path = path.dup

  path[':session_id'] = session_id if path.include?(':session_id')

  begin
    opts.each { |key, value| path[key.inspect] = escaper.escape(value.to_s) }
  rescue IndexError
    raise ArgumentError, "#{opts.inspect} invalid for #{command.inspect}"
  end

  WebDriver.logger.debug("-> #{verb.to_s.upcase} #{path}", id: :command)
  http.call(verb, path, command_hash)['value']
end

#execute_async_script(script, *args)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 337

def execute_async_script(script, *args)
  result = execute :execute_async_script, {}, {script: script, args: args}
  unwrap_script_result result
end

#execute_script(script, *args)

javascript execution

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 332

def execute_script(script, *args)
  result = execute :execute_script, {}, {script: script, args: args}
  unwrap_script_result result
end

#find_element_by(how, what, parent_ref = [])

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 508

def find_element_by(how, what, parent_ref = [])
  how, what = convert_locator(how, what)

  return execute_atom(:findElements, Support::RelativeLocator.new(what).as_json).first if how == 'relative'

  parent_type, parent_id = parent_ref
  id = case parent_type
       when :element
         execute :find_child_element, {id: parent_id}, {using: how, value: what.to_s}
       when :shadow_root
         execute :find_shadow_child_element, {id: parent_id}, {using: how, value: what.to_s}
       else
         execute :find_element, {}, {using: how, value: what.to_s}
       end

  Element.new self, element_id_from(id)
end

#find_elements_by(how, what, parent_ref = [])

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 526

def find_elements_by(how, what, parent_ref = [])
  how, what = convert_locator(how, what)

  return execute_atom :findElements, Support::RelativeLocator.new(what).as_json if how == 'relative'

  parent_type, parent_id = parent_ref
  ids = case parent_type
        when :element
          execute :find_child_elements, {id: parent_id}, {using: how, value: what.to_s}
        when :shadow_root
          execute :find_shadow_child_elements, {id: parent_id}, {using: how, value: what.to_s}
        else
          execute :find_elements, {}, {using: how, value: what.to_s}
        end

  ids.map { |id| Element.new self, element_id_from(id) }
end

#full_screen_window

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 244

def full_screen_window
  execute :fullscreen_window
end

#get(url)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 95

def get(url)
  execute :get, {}, {url: url}
end

#go_back

navigation

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 135

def go_back
  execute :back
end

#go_forward

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 139

def go_forward
  execute :forward
end

#local_storage_item(key, value = nil)

HTML 5

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 280

def local_storage_item(key, value = nil)
  if value
    execute_script("localStorage.setItem('#{key}', '#{value}')")
  else
    execute_script("return localStorage.getItem('#{key}')")
  end
end

#local_storage_keys

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 292

def local_storage_keys
  execute_script('return Object.keys(localStorage)')
end

#local_storage_size

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 300

def local_storage_size
  execute_script('return localStorage.length')
end

#manage

cookies

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 346

def manage
  @manage ||= WebDriver::Manager.new(self)
end

#maximize_window(handle = :current)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 235

def maximize_window(handle = :current)
  unless handle == :current
    raise Error::UnsupportedOperationError,
          'Switch to desired window before changing its size'
  end

  execute :maximize_window
end

#minimize_window

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 231

def minimize_window
  execute :minimize_window
end

#new_window(type) ⇒ Hash

Create a new top-level browsing context w3c.github.io/webdriver/#new-window

Parameters:

  • type (String)

    Supports two values: ‘tab’ and ‘window’. Use ‘tab’ if you’d like the new window to share an OS-level window with the current browsing context. Use ‘window’ otherwise

Returns:

  • (Hash)

    Containing ‘handle’ with the value of the window handle and ‘type’ with the value of the created window type

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 165

def new_window(type)
  execute :new_window, {}, {type: type}
end

#page_source

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 151

def page_source
  execute :get_page_source
end

#prepare_capabilities_payload(capabilities) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 643

def prepare_capabilities_payload(capabilities)
  capabilities = {alwaysMatch: capabilities} if !capabilities['alwaysMatch'] && !capabilities['firstMatch']
  {capabilities: capabilities}
end

#quit

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 188

def quit
  execute :delete_session
  http.close
rescue *QUIT_ERRORS
  nil
end

#refresh

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 199

def refresh
  execute :refresh
end

#release_actions

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 383

def release_actions
  execute :release_actions
end

#remove_all_credentials(authenticator_id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 574

def remove_all_credentials(authenticator_id)
  execute :remove_all_credentials, {authenticatorId: authenticator_id}
end

#remove_credential(credential_id, authenticator_id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 570

def remove_credential(credential_id, authenticator_id)
  execute :remove_credential, {credentialId: credential_id, authenticatorId: authenticator_id}
end

#remove_local_storage_item(key)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 288

def remove_local_storage_item(key)
  execute_script("localStorage.removeItem('#{key}')")
end

#remove_session_storage_item(key)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 312

def remove_session_storage_item(key)
  execute_script("sessionStorage.removeItem('#{key}')")
end

#remove_virtual_authenticator(id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 558

def remove_virtual_authenticator(id)
  execute :remove_virtual_authenticator, {authenticatorId: id}
end

#reposition_window(x, y)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 248

def reposition_window(x, y)
  set_window_rect(x: x, y: y)
end

#resize_window(width, height, handle = :current)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 215

def resize_window(width, height, handle = :current)
  raise Error::WebDriverError, 'Switch to desired window before changing its size' unless handle == :current

  set_window_rect(width: width, height: height)
end

#screenshot

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 268

def screenshot
  execute :take_screenshot
end

#send_actions(data)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 379

def send_actions(data)
  execute :actions, {}, {actions: data}
end

#send_keys_to_element(element, keys)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 395

def send_keys_to_element(element, keys)
  keys = upload_if_necessary(keys) if @file_detector
  text = keys.join
  execute :element_send_keys, {id: element}, {value: text.chars, text: text}
end

#session_id

Returns the current session ID.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 80

def session_id
  @session_id || raise(Error::WebDriverError, 'no current session exists')
end

#session_storage_item(key, value = nil)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 304

def session_storage_item(key, value = nil)
  if value
    execute_script("sessionStorage.setItem('#{key}', '#{value}')")
  else
    execute_script("return sessionStorage.getItem('#{key}')")
  end
end

#session_storage_keys

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 316

def session_storage_keys
  execute_script('return Object.keys(sessionStorage)')
end

#session_storage_size

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 324

def session_storage_size
  execute_script('return sessionStorage.length')
end

#set_window_rect(x: nil, y: nil, width: nil, height: nil)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 257

def set_window_rect(x: nil, y: nil, width: nil, height: nil)
  params = {x: x, y: y, width: width, height: height}
  params.update(params) { |_k, v| Integer(v) unless v.nil? }
  execute :set_window_rect, {}, params
end

#shadow_root(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 544

def shadow_root(element)
  id = execute :get_element_shadow_root, id: element
  ShadowRoot.new self, shadow_root_id_from(id)
end

#shadow_root_id_from(id) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 639

def shadow_root_id_from(id)
  id[ShadowRoot::ROOT_KEY]
end

#status

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 91

def status
  execute :status
end

#submit_element(element)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 405

def submit_element(element)
  script = "/* submitForm */ var form = arguments[0];\n" \
           "while (form.nodeName != \"FORM\" && form.parentNode) {\n  " \
           "form = form.parentNode;\n" \
           "}\n" \
           "if (!form) { throw Error('Unable to find containing form element'); }\n" \
           "if (!form.ownerDocument) { throw Error('Unable to find owning document'); }\n" \
           "var e = form.ownerDocument.createEvent('Event');\n" \
           "e.initEvent('submit', true, true);\n" \
           "if (form.dispatchEvent(e)) { HTMLFormElement.prototype.submit.call(form) }\n"

  execute_script(script, Element::ELEMENT_KEY => element)
rescue Error::JavascriptError
  raise Error::UnsupportedOperationError, 'To submit an element, it must be nested inside a form element'
end

#switch_to_active_element

Alias for #active_element.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 506

alias switch_to_active_element active_element

#switch_to_default_content

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 182

def switch_to_default_content
  switch_to_frame nil
end

#switch_to_frame(id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 173

def switch_to_frame(id)
  id = find_element_by('id', id) if id.is_a? String
  execute :switch_to_frame, {}, {id: id}
end

#switch_to_parent_frame

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 178

def switch_to_parent_frame
  execute :switch_to_parent_frame
end

#switch_to_window(name)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 169

def switch_to_window(name)
  execute :switch_to_window, {}, {handle: name}
end

#title

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 147

def title
  execute :get_title
end

#unwrap_script_result(arg) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 618

def unwrap_script_result(arg)
  case arg
  when Array
    arg.map { |e| unwrap_script_result(e) }
  when Hash
    element_id = element_id_from(arg)
    return Element.new(self, element_id) if element_id

    shadow_root_id = shadow_root_id_from(arg)
    return ShadowRoot.new self, shadow_root_id if shadow_root_id

    arg.each { |k, v| arg[k] = unwrap_script_result(v) }
  else
    arg
  end
end

#url

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 143

def url
  execute :get_current_url
end

#user_verified(verified, authenticator_id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 578

def user_verified(verified, authenticator_id)
  execute :set_user_verified, {authenticatorId: authenticator_id}, {isUserVerified: verified}
end

#window_handle

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 211

def window_handle
  execute :get_window_handle
end

#window_handles

window handling

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 207

def window_handles
  execute :get_window_handles
end

#window_position

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 252

def window_position
  data = execute :get_window_rect
  Point.new data['x'], data['y']
end

#window_rect

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 263

def window_rect
  data = execute :get_window_rect
  Rectangle.new data['x'], data['y'], data['width'], data['height']
end

#window_size(handle = :current)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/bridge.rb', line 221

def window_size(handle = :current)
  unless handle == :current
    raise Error::UnsupportedOperationError,
          'Switch to desired window before getting its size'
  end

  data = execute :get_window_rect
  Dimension.new data['width'], data['height']
end