class Selenium::WebDriver::Remote::W3C::Bridge
Low level bridge to the remote server implementing JSON wire protocol (W3C dialect), through which the rest of the API works. @api private
www.w3.org/TR/2015/WD-webdriver-20150918/#list-of-endpoints @api private
Constants
- COMMANDS
- ESCAPE_CSS_REGEXP
- QUIT_ERRORS
- UNICODE_CODE_POINT
Public Class Methods
new(capabilities, session_id, **opts)
click to toggle source
Calls superclass method
Selenium::WebDriver::Remote::Bridge::new
# File lib/selenium/webdriver/remote/w3c/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/w3c/bridge.rb, line 77 def accept_alert execute :accept_alert end
action(async = false)
click to toggle source
actions
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 333 def action(async = false) W3CActionBuilder.new self, Interactions.pointer(:mouse, name: 'mouse'), Interactions.key('keyboard'), async end
Also aliased as: actions
active_element()
click to toggle source
finding elements
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 520 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/w3c/bridge.rb, line 85 def alert=(keys) execute :send_alert_text, {}, {value: keys.split(//), text: keys} end
alert_text()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 89 def alert_text execute :get_alert_text end
clear_element(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 385 def clear_element(element) execute :element_clear, id: element end
clear_local_storage()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 239 def clear_local_storage execute_script('localStorage.clear()') end
clear_session_storage()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 263 def clear_session_storage execute_script('sessionStorage.clear()') end
click_element(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 357 def click_element(element) execute :element_click, id: element end
close()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 144 def close execute :close_window end
commands(command)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 43 def commands(command) case command when :status Remote::OSS::Bridge::COMMANDS[command] else COMMANDS[command] end end
dialect()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 39 def dialect :w3c end
dismiss_alert()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 81 def dismiss_alert execute :dismiss_alert end
drag_element(element, right_by, down_by)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/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/w3c/bridge.rb, line 461 def element_attribute(element, name) execute_atom :getAttribute, element, name end
element_displayed?(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 508 def element_displayed?(element) execute_atom :isDisplayed, element end
element_enabled?(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 500 def element_enabled?(element) execute :is_element_enabled, id: element end
element_location(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 477 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)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 489 def element_location_once_scrolled_into_view(element) send_keys_to_element(element, ['']) element_location(element) end
element_property(element, name)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 465 def element_property(element, name) execute :get_element_property, id: element.ref, name: name end
element_rect(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 483 def element_rect(element) data = execute :get_element_rect, id: element Rectangle.new data['x'], data['y'], data['width'], data['height'] end
element_selected?(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 504 def element_selected?(element) execute :is_element_selected, id: element end
element_size(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 494 def element_size(element) data = execute :get_element_rect, id: element Dimension.new data['width'], data['height'] end
element_tag_name(element)
click to toggle source
element properties
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 457 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/w3c/bridge.rb, line 473 def element_text(element) execute :get_element_text, id: element end
element_value(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 469 def element_value(element) element_property element, 'value' end
element_value_of_css_property(element, prop)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 512 def element_value_of_css_property(element, prop) execute :get_element_css_value, id: element, property_name: prop end
execute_async_script(script, *args)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 296 def execute_async_script(script, *args) 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/w3c/bridge.rb, line 291 def execute_script(script, *args) 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/w3c/bridge.rb, line 526 def find_element_by(how, what, parent = nil) how, what = convert_locators(how, what) 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/w3c/bridge.rb, line 537 def find_elements_by(how, what, parent = nil) how, what = convert_locators(how, what) ids = if parent execute :find_child_elements, {id: parent}, {using: how, value: what} else execute :find_elements, {}, {using: how, value: what} end ids.map { |id| Element.new self, element_id_from(id) } end
full_screen_window()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 191 def full_screen_window execute :fullscreen_window end
get(url)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 56 def get(url) execute :get, {}, {url: url} end
go_back()
click to toggle source
navigation
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 97 def go_back execute :back end
go_forward()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 101 def go_forward execute :forward end
implicit_wait_timeout=(milliseconds)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 60 def implicit_wait_timeout=(milliseconds) timeout('implicit', milliseconds) end
keyboard()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 345 def keyboard raise Error::UnsupportedOperationError, '#keyboard is no longer supported, use #action instead' end
local_storage_item(key, value = nil)
click to toggle source
HTML 5
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 223 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()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 235 def local_storage_keys execute_script('return Object.keys(localStorage)') end
local_storage_size()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 243 def local_storage_size execute_script('return localStorage.length') end
location()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 271 def location raise Error::UnsupportedOperationError, 'The W3C standard does not currently support getting location' end
maximize_window(handle = :current)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 184 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()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 180 def minimize_window execute :minimize_window end
mouse()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 341 def mouse raise Error::UnsupportedOperationError, '#mouse is no longer supported, use #action instead' end
network_connection()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 279 def network_connection raise Error::UnsupportedOperationError, 'The W3C standard does not currently support getting network connection' end
network_connection=(_type)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 283 def network_connection=(_type) raise Error::UnsupportedOperationError, 'The W3C standard does not currently support setting network connection' end
options()
click to toggle source
cookies
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 305 def options @options ||= WebDriver::W3COptions.new(self) end
page_source()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 113 def page_source execute_script('var source = document.documentElement.outerHTML;' \ 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \ 'return source;') end
quit()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 138 def quit execute :delete_session http.close rescue *QUIT_ERRORS end
refresh()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 148 def refresh execute :refresh end
release_actions()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 353 def release_actions execute :release_actions end
remove_local_storage_item(key)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 231 def remove_local_storage_item(key) execute_script("localStorage.removeItem('#{key}')") end
remove_session_storage_item(key)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 255 def remove_session_storage_item(key) execute_script("sessionStorage.removeItem('#{key}')") end
reposition_window(x, y)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 195 def reposition_window(x, y) set_window_rect(x: x, y: y) end
resize_window(width, height, handle = :current)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 164 def resize_window(width, height, handle = :current) unless handle == :current raise Error::WebDriverError, 'Switch to desired window before changing its size' end set_window_rect(width: width, height: height) end
screen_orientation()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 449 def screen_orientation execute :get_screen_orientation end
screen_orientation=(orientation)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/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/w3c/bridge.rb, line 215 def screenshot execute :take_screenshot end
script_timeout=(milliseconds)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 64 def script_timeout=(milliseconds) timeout('script', milliseconds) end
send_actions(data)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 349 def send_actions(data) execute :actions, {}, {actions: data} end
send_keys_to_element(element, keys)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 361 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 = Array(keys.join("\n")) end end # Keep .split(//) for backward compatibility for now text = keys.join('') execute :element_send_keys, {id: element}, {value: text.split(//), text: text} end
session_storage_item(key, value = nil)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 247 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()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 259 def session_storage_keys execute_script('return Object.keys(sessionStorage)') end
session_storage_size()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 267 def session_storage_size execute_script('return sessionStorage.length') end
set_location(_lat, _lon, _alt)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 275 def set_location(_lat, _lon, _alt) raise Error::UnsupportedOperationError, 'The W3C standard does not currently support setting location' end
set_window_rect(x: nil, y: nil, width: nil, height: nil)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 204 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
status()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 52 def status execute :status end
submit_element(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 389 def submit_element(element) form = find_element_by('xpath', "./ancestor-or-self::form", element) execute_script("var e = arguments[0].ownerDocument.createEvent('Event');" \ "e.initEvent('submit', true, true);" \ 'if (arguments[0].dispatchEvent(e)) { arguments[0].submit() }', form.as_json) end
switch_to_default_content()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 132 def switch_to_default_content switch_to_frame nil end
switch_to_frame(id)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 123 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()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 128 def switch_to_parent_frame execute :switch_to_parent_frame end
switch_to_window(name)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 119 def switch_to_window(name) execute :switch_to_window, {}, {handle: name} end
timeout(type, milliseconds)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 68 def timeout(type, milliseconds) type = 'pageLoad' if type == 'page load' execute :set_timeout, {}, {type => milliseconds} end
title()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 109 def title execute :get_title end
touch_double_tap(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/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/w3c/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/w3c/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/w3c/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/w3c/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/w3c/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/w3c/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/w3c/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/w3c/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/w3c/bridge.rb, line 376 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/w3c/bridge.rb, line 105 def url execute :get_current_url end
window_handle()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 160 def window_handle execute :get_window_handle end
window_handles()
click to toggle source
window handling
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 156 def window_handles execute :get_window_handles end
window_position()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 199 def window_position data = execute :get_window_rect Point.new data['x'], data['y'] end
window_rect()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 210 def window_rect data = execute :get_window_rect Rectangle.new data['x'], data['y'], data['width'], data['height'] end
window_size(handle = :current)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 171 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
Private Instance Methods
convert_locators(how, what)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 555 def convert_locators(how, what) case how when 'class name' how = 'css selector' what = ".#{escape_css(what)}" when 'id' how = 'css selector' what = "##{escape_css(what)}" when 'name' how = 'css selector' what = "*[name='#{escape_css(what)}']" when 'tag name' how = 'css selector' end [how, what] end
escape_css(string)
click to toggle source
Escapes invalid characters in CSS selector. @see mathiasbynens.be/notes/css-escapes
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 577 def escape_css(string) string = string.gsub(ESCAPE_CSS_REGEXP) { |match| "\\#{match}" } if !string.empty? && string[0] =~ /[[:digit:]]/ string = "\\#{UNICODE_CODE_POINT + Integer(string[0])} #{string[1..-1]}" end string end
execute(*)
click to toggle source
Calls superclass method
Selenium::WebDriver::Remote::Bridge#execute
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 551 def execute(*) super['value'] end