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 35 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 79 def accept_alert execute :accept_alert end
action(async = false)
click to toggle source
actions
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 346 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 535 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 87 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 91 def alert_text execute :get_alert_text end
clear_element(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 398 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 252 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 276 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 370 def click_element(element) execute :element_click, id: element end
close()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 160 def close execute :close_window end
commands(command)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 45 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 41 def dialect :w3c end
dismiss_alert()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 83 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 409 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 474 def element_attribute(element, name) WebDriver.logger.info "Using script for :getAttribute of #{name}" execute_atom :getAttribute, element, name end
element_displayed?(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 522 def element_displayed?(element) WebDriver.logger.info 'Using script for :isDisplayed' execute_atom :isDisplayed, element end
element_enabled?(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 514 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 491 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 503 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 479 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 497 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 518 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 508 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 470 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 487 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 483 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 527 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 309 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 304 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 541 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 552 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 204 def full_screen_window execute :fullscreen_window end
get(url)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 58 def get(url) execute :get, {}, {url: url} end
go_back()
click to toggle source
navigation
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 99 def go_back execute :back end
go_forward()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 103 def go_forward execute :forward end
implicit_wait_timeout=(milliseconds)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 62 def implicit_wait_timeout=(milliseconds) timeout('implicit', milliseconds) end
keyboard()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 358 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 236 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 248 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 256 def local_storage_size execute_script('return localStorage.length') end
location()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 284 def location raise Error::UnsupportedOperationError, 'The W3C standard does not currently support getting location' end
manage()
click to toggle source
cookies
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 318 def manage @manage ||= WebDriver::W3CManager.new(self) end
maximize_window(handle = :current)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 198 def maximize_window(handle = :current) raise Error::UnsupportedOperationError, 'Switch to desired window before changing its size' unless handle == :current execute :maximize_window end
minimize_window()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 194 def minimize_window execute :minimize_window end
mouse()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 354 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 292 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 296 def network_connection=(_type) raise Error::UnsupportedOperationError, 'The W3C standard does not currently support setting network connection' end
new_window(type)
click to toggle source
Create a new top-level browsing context w3c.github.io/webdriver/#new-window @param 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
@return [Hash] Containing 'handle' with the value of the window handle
and 'type' with the value of the created window type
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 131 def new_window(type) execute :new_window, {}, {type: type} end
page_source()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 115 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 154 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 164 def refresh execute :refresh end
release_actions()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 366 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 244 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 268 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 208 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 180 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
screen_orientation()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 462 def screen_orientation execute :get_screen_orientation end
screen_orientation=(orientation)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 458 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 228 def screenshot execute :take_screenshot end
script_timeout=(milliseconds)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 66 def script_timeout=(milliseconds) timeout('script', milliseconds) end
send_actions(data)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 362 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 374 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 260 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 272 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 280 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 288 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 217 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 54 def status execute :status end
submit_element(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 402 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 148 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 139 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 144 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 135 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 70 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 111 def title execute :get_title end
touch_double_tap(element)
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 417 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 425 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 451 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 447 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 421 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 433 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 437 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 413 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 429 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 389 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 107 def url execute :get_current_url end
window_handle()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 176 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 172 def window_handles execute :get_window_handles end
window_position()
click to toggle source
# File lib/selenium/webdriver/remote/w3c/bridge.rb, line 212 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 223 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 186 def window_size(handle = :current) raise Error::UnsupportedOperationError, 'Switch to desired window before getting its size' unless handle == :current 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 570 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 592 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 566 def execute(*) super['value'] end