class Selenium::WebDriver::Remote::OSS::Bridge

Low level bridge to the remote server implementing JSON wire protocol (OSS dialect), through which the rest of the API works. @api private

github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-reference @api private

Constants

COMMANDS

Public Class Methods

new(capabilities, session_id, **opts) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 33
def initialize(capabilities, session_id, **opts)
  @capabilities = capabilities
  @session_id = session_id
  super(opts)
end

Public Instance Methods

accept_alert() click to toggle source

alerts

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 75
def accept_alert
  execute :accept_alert
end
action() click to toggle source

@return [ActionBuilder] @api public

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 313
def action
  ActionBuilder.new Mouse.new(self), Keyboard.new(self)
end
active_element() click to toggle source

finding elements

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 544
def active_element
  Element.new self, element_id_from(execute(:get_active_element))
end
Also aliased as: switch_to_active_element
alert=(keys) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 83
def alert=(keys)
  execute :set_alert_value, {}, {text: keys.to_s}
end
alert_text() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 87
def alert_text
  execute :get_alert_text
end
authentication(credentials) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 91
def authentication(credentials)
  execute :set_authentication, {}, credentials
end
available_log_types() click to toggle source

logs

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 457
def available_log_types
  types = execute :get_available_log_types
  Array(types).map(&:to_sym)
end
clear_element(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 388
def clear_element(element)
  execute :clear_element, id: element
end
clear_local_storage() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 212
def clear_local_storage
  execute :clear_local_storage
end
clear_session_storage() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 236
def clear_session_storage
  execute :clear_session_storage
end
click() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 331
def click
  execute :click, {}, {button: 0}
end
click_element(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 327
def click_element(element)
  execute :click_element, id: element
end
close() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 141
def close
  execute :close
end
commands(command) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 43
def commands(command)
  COMMANDS[command]
end
context_click() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 339
def context_click
  execute :click, {}, {button: 2}
end
cookies() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 296
def cookies
  execute :get_cookies
end
delete_all_cookies() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 300
def delete_all_cookies
  execute :delete_all_cookies
end
dialect() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 39
def dialect
  :oss
end
dismiss_alert() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 79
def dismiss_alert
  execute :dismiss_alert
end
double_click() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 335
def double_click
  execute :double_click
end
drag_element(element, right_by, down_by) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 396
def drag_element(element, right_by, down_by)
  execute :drag_element, {id: element}, {x: right_by, y: down_by}
end
element_attribute(element, name) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 482
def element_attribute(element, name)
  execute :get_element_attribute, id: element.ref, name: name
end
element_displayed?(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 532
def element_displayed?(element)
  execute :is_element_displayed, id: element.ref
end
element_enabled?(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 524
def element_enabled?(element)
  execute :is_element_enabled, id: element
end
element_location(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 499
def element_location(element)
  data = execute :get_element_location, id: element

  Point.new data['x'], data['y']
end
element_location_once_scrolled_into_view(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 512
def element_location_once_scrolled_into_view(element)
  data = execute :get_element_location_once_scrolled_into_view, id: element

  Point.new data['x'], data['y']
end
element_property(element, name) click to toggle source

Backwards compatibility for w3c

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 487
def element_property(element, name)
  execute_script 'return arguments[0][arguments[1]]', element, name
end
element_rect(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 505
def element_rect(element)
  loc = execute :get_element_location, id: element
  size = execute :get_element_size, id: element

  Rectangle.new loc['x'], loc['y'], size['width'], size['height']
end
element_selected?(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 528
def element_selected?(element)
  execute :is_element_selected, id: element
end
element_size(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 518
def element_size(element)
  data = execute :get_element_size, id: element

  Dimension.new data['width'], data['height']
end
element_tag_name(element) click to toggle source

element properties

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 478
def element_tag_name(element)
  execute :get_element_tag_name, id: element
end
element_text(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 495
def element_text(element)
  execute :get_element_text, id: element
end
element_value(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 491
def element_value(element)
  execute :get_element_value, id: element
end
element_value_of_css_property(element, prop) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 536
def element_value_of_css_property(element, prop)
  execute :get_element_value_of_css_property, id: element, property_name: prop
end
execute_async_script(script, *args) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 273
def execute_async_script(script, *args)
  assert_javascript_enabled

  result = execute :execute_async_script, {}, {script: script, args: args}
  unwrap_script_result result
end
execute_script(script, *args) click to toggle source

javascript execution

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 266
def execute_script(script, *args)
  assert_javascript_enabled

  result = execute :execute_script, {}, {script: script, args: args}
  unwrap_script_result result
end
find_element_by(how, what, parent = nil) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 550
def find_element_by(how, what, parent = nil)
  id = if parent
         execute :find_child_element, {id: parent}, {using: how, value: what}
       else
         execute :find_element, {}, {using: how, value: what}
       end

  Element.new self, element_id_from(id)
end
find_elements_by(how, what, parent = nil) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 560
def find_elements_by(how, what, parent = nil)
  ids = if parent
          execute :find_child_elements, {id: parent}, {using: how, value: what}
        else
          execute :find_elements, {}, {using: how, value: what}
        end
  # see https://github.com/SeleniumHQ/selenium/issues/4555
  ids ||= []

  ids.map { |id| Element.new self, element_id_from(id) }
end
get(url) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 51
def get(url)
  execute :get, {}, {url: url}
end
go_back() click to toggle source

navigation

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 99
def go_back
  execute :go_back
end
go_forward() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 103
def go_forward
  execute :go_forward
end
implicit_wait_timeout=(milliseconds) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 59
def implicit_wait_timeout=(milliseconds)
  execute :implicitly_wait, {}, {ms: milliseconds}
end
keyboard() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 322
def keyboard
  WebDriver.logger.deprecate 'Driver#keyboard', 'driver.action.<command>.perform'
  Keyboard.new self
end
local_storage_item(key, value = nil) click to toggle source

HTML 5

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 196
def local_storage_item(key, value = nil)
  if value
    execute :set_local_storage_item, {}, {key: key, value: value}
  else
    execute :get_local_storage_item, key: key
  end
end
local_storage_keys() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 208
def local_storage_keys
  execute :get_local_storage_keys
end
local_storage_size() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 216
def local_storage_size
  execute :get_local_storage_size
end
location() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 244
def location
  obj = execute(:get_location) || {}
  Location.new obj['latitude'], obj['longitude'], obj['altitude']
end
log(type) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 462
def log(type)
  data = execute :get_log, {}, {type: type.to_s}

  Array(data).map do |l|
    begin
      LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
    rescue KeyError
      next
    end
  end
end
manage() click to toggle source

cookies

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 284
def manage
  @manage ||= WebDriver::Manager.new(self)
end
maximize_window(handle = :current) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 167
def maximize_window(handle = :current)
  execute :maximize_window, window_handle: handle
end
mouse() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 317
def mouse
  WebDriver.logger.deprecate 'Driver#mouse', 'driver.action.<command>.perform'
  Mouse.new self
end
mouse_down() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 343
def mouse_down
  execute :mouse_down
end
mouse_move_to(element, x = nil, y = nil) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 351
def mouse_move_to(element, x = nil, y = nil)
  params = {element: element}

  if x && y
    params[:xoffset] = x
    params[:yoffset] = y
  end

  execute :mouse_move_to, {}, params
end
mouse_up() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 347
def mouse_up
  execute :mouse_up
end
network_connection() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 254
def network_connection
  execute :get_network_connection
end
network_connection=(type) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 258
def network_connection=(type)
  execute :set_network_connection, {}, {parameters: {type: type}}
end
page_source() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 115
def page_source
  execute :get_page_source
end
quit() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 135
def quit
  execute :quit
  http.close
rescue *http.quit_errors
end
refresh() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 145
def refresh
  execute :refresh
end
remove_local_storage_item(key) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 204
def remove_local_storage_item(key)
  execute :remove_local_storage_item, key: key
end
remove_session_storage_item(key) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 228
def remove_session_storage_item(key)
  execute :remove_session_storage_item, key: key
end
reposition_window(x, y, handle = :current) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 177
def reposition_window(x, y, handle = :current)
  execute :set_window_position, {window_handle: handle},
          {x: x, y: y}
end
resize_window(width, height, handle = :current) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 161
def resize_window(width, height, handle = :current)
  execute :set_window_size, {window_handle: handle},
          {width: width,
           height: height}
end
screen_orientation() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 449
def screen_orientation
  execute :get_screen_orientation
end
screen_orientation=(orientation) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 445
def screen_orientation=(orientation)
  execute :set_screen_orientation, {}, {orientation: orientation}
end
screenshot() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 188
def screenshot
  execute :screenshot
end
script_timeout=(milliseconds) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 63
def script_timeout=(milliseconds)
  execute :set_script_timeout, {}, {ms: milliseconds}
end
send_keys_to_active_element(key) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 362
def send_keys_to_active_element(key)
  execute :send_keys_to_active_element, {}, {value: key}
end
send_keys_to_element(element, keys) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 366
def send_keys_to_element(element, keys)
  # TODO: rework file detectors before Selenium 4.0
  if @file_detector
    local_files = keys.first.split("\n").map { |key| @file_detector.call(Array(key)) }.compact
    if local_files.any?
      keys = local_files.map { |local_file| upload(local_file) }
      keys = keys.join("\n")
    end
  end

  execute :send_keys_to_element, {id: element}, {value: Array(keys)}
end
session_capabilities() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 55
def session_capabilities
  Capabilities.json_create execute(:get_capabilities)
end
session_storage_item(key, value = nil) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 220
def session_storage_item(key, value = nil)
  if value
    execute :set_session_storage_item, {}, {key: key, value: value}
  else
    execute :get_session_storage_item, key: key
  end
end
session_storage_keys() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 232
def session_storage_keys
  execute :get_session_storage_keys
end
session_storage_size() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 240
def session_storage_size
  execute :get_session_storage_size
end
set_location(lat, lon, alt) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 249
def set_location(lat, lon, alt)
  loc = {latitude: lat, longitude: lon, altitude: alt}
  execute :set_location, {}, {location: loc}
end
status() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 47
def status
  execute :status
end
submit_element(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 392
def submit_element(element)
  execute :submit_element, id: element
end
switch_to_active_element()
Alias for: active_element
switch_to_default_content() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 131
def switch_to_default_content
  switch_to_frame(nil)
end
switch_to_frame(id) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 123
def switch_to_frame(id)
  execute :switch_to_frame, {}, {id: id}
end
switch_to_parent_frame() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 127
def switch_to_parent_frame
  execute :switch_to_parent_frame
end
switch_to_window(name) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 119
def switch_to_window(name)
  execute :switch_to_window, {}, {name: name}
end
timeout(type, milliseconds) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 67
def timeout(type, milliseconds)
  execute :set_timeout, {}, {type: type, ms: milliseconds}
end
title() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 111
def title
  execute :get_title
end
touch_double_tap(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 404
def touch_double_tap(element)
  execute :touch_double_tap, {}, {element: element}
end
touch_down(x, y) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 412
def touch_down(x, y)
  execute :touch_down, {}, {x: x, y: y}
end
touch_element_flick(element, right_by, down_by, speed) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 438
def touch_element_flick(element, right_by, down_by, speed)
  execute :touch_flick, {}, {element: element,
                             xoffset: right_by,
                             yoffset: down_by,
                             speed: speed}
end
touch_flick(xspeed, yspeed) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 434
def touch_flick(xspeed, yspeed)
  execute :touch_flick, {}, {xspeed: xspeed, yspeed: yspeed}
end
touch_long_press(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 408
def touch_long_press(element)
  execute :touch_long_press, {}, {element: element}
end
touch_move(x, y) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 420
def touch_move(x, y)
  execute :touch_move, {}, {x: x, y: y}
end
touch_scroll(element, x, y) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 424
def touch_scroll(element, x, y)
  if element
    execute :touch_scroll, {}, {element: element,
                                xoffset: x,
                                yoffset: y}
  else
    execute :touch_scroll, {}, {xoffset: x, yoffset: y}
  end
end
touch_single_tap(element) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 400
def touch_single_tap(element)
  execute :touch_single_tap, {}, {element: element}
end
touch_up(x, y) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 416
def touch_up(x, y)
  execute :touch_up, {}, {x: x, y: y}
end
upload(local_file) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 379
def upload(local_file)
  unless File.file?(local_file)
    WebDriver.logger.debug("File detector only works with files. #{local_file.inspect} isn`t a file!")
    raise Error::WebDriverError, "You are trying to work with something that isn't a file."
  end

  execute :upload_file, {}, {file: Zipper.zip_file(local_file)}
end
url() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 107
def url
  execute :get_current_url
end
window_handle() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 157
def window_handle
  execute :get_current_window_handle
end
window_handles() click to toggle source

window handling

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 153
def window_handles
  execute :get_window_handles
end
window_position(handle = :current) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 182
def window_position(handle = :current)
  data = execute :get_window_position, window_handle: handle

  Point.new data['x'], data['y']
end
window_size(handle = :current) click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 171
def window_size(handle = :current)
  data = execute :get_window_size, window_handle: handle

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

Private Instance Methods

assert_javascript_enabled() click to toggle source
# File lib/selenium/webdriver/remote/oss/bridge.rb, line 574
def assert_javascript_enabled
  return if capabilities.javascript_enabled?

  raise Error::UnsupportedOperationError, 'underlying webdriver instance does not support javascript'
end
execute(*args) click to toggle source

executes a command on the remote server.

Returns the 'value' of the returned payload

# File lib/selenium/webdriver/remote/oss/bridge.rb, line 586
def execute(*args)
  super['value']
end