class Selenium::WebDriver::Remote::Bridge
w3c.github.io/webdriver/#endpoints @api private
Constants
- COMMANDS
- PORT
- QUIT_ERRORS
Attributes
Public Class Methods
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 38 def add_command(name, verb, url, &block) @extra_commands ||= {} @extra_commands[name] = [verb, url] define_method(name, &block) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 48 def element_class @element_class ||= Element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 44 def locator_converter @locator_converter ||= LocatorConverter.new end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 60 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 @locator_converter = self.class.locator_converter end
Initializes the bridge with the given server URL @param [String, URI] url url for the remote server @param [Object] http_client an HTTP client instance that implements the same protocol as Http::Default @api private
Public Instance Methods
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 138 def accept_alert execute :accept_alert end
alerts
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 347 def action(async: false, devices: [], duration: 250) ActionBuilder.new self, async: async, devices: devices, duration: duration end
actions
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 475 def active_element Bridge.element_class.new self, element_id_from(execute(:get_active_element)) end
finding elements
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 535 def add_credential(credential, id) execute :add_credential, {authenticatorId: id}, credential end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 526 def add_virtual_authenticator(options) authenticator_id = execute :add_virtual_authenticator, {}, options.as_json VirtualAuthenticator.new(self, authenticator_id, options) end
virtual-authenticator
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 146 def alert=(keys) execute :send_alert_text, {}, {value: keys.chars, text: keys} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 150 def alert_text execute :get_alert_text end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 595 def bidi msg = 'BiDi must be enabled by setting #web_socket_url to true in options class' raise(WebDriver::Error::WebDriverError, msg) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 107 def browser @browser ||= begin name = @capabilities.browser_name name ? name.tr(' -', '_').downcase.to_sym : 'unknown' end end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 559 def cancel_fedcm_dialog execute :cancel_fedcm_dialog end
federated-credential management
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 374 def clear_element(element) execute :element_clear, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 364 def click_element(element) execute :element_click, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 218 def close execute :close_window end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 600 def command_list COMMANDS end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 75 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
Creates session.
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 539 def credentials(authenticator_id) execute :get_credentials, {authenticatorId: authenticator_id} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 142 def dismiss_alert execute :dismiss_alert end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 419 def element_aria_label(element) execute :get_element_aria_label, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 415 def element_aria_role(element) execute :get_element_aria_role, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 402 def element_attribute(element, name) WebDriver.logger.debug "Using script for :getAttribute of #{name}", id: :script execute_atom :getAttribute, element, name end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 462 def element_displayed?(element) WebDriver.logger.debug 'Using script for :isDisplayed', id: :script execute_atom :isDisplayed, element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 407 def element_dom_attribute(element, name) execute :get_element_attribute, id: element, name: name end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 454 def element_enabled?(element) execute :is_element_enabled, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 431 def element_location(element) data = execute :get_element_rect, id: element Point.new data['x'], data['y'] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 443 def element_location_once_scrolled_into_view(element) send_keys_to_element(element, ['']) element_location(element) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 411 def element_property(element, name) execute :get_element_property, id: element, name: name end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 437 def element_rect(element) data = execute :get_element_rect, id: element Rectangle.new data['x'], data['y'], data['width'], data['height'] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 295 def element_screenshot(element) execute :take_element_screenshot, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 458 def element_selected?(element) execute :is_element_selected, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 448 def element_size(element) data = execute :get_element_rect, id: element Dimension.new data['width'], data['height'] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 398 def element_tag_name(element) execute :get_element_tag_name, id: element end
element properties
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 427 def element_text(element) execute :get_element_text, id: element end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 423 def element_value(element) element_property element, 'value' end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 467 def element_value_of_css_property(element, prop) execute :get_element_css_value, id: element, property_name: prop end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 308 def execute_async_script(script, *args) result = execute :execute_async_script, {}, {script: script, args: args} unwrap_script_result result end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 303 def execute_script(script, *args) result = execute :execute_script, {}, {script: script, args: args} unwrap_script_result result end
javascript execution
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 579 def fedcm_account_list execute :get_fedcm_account_list end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 583 def fedcm_delay(enabled) execute :set_fedcm_delay, {}, {enabled: enabled} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 567 def fedcm_dialog_type execute :get_fedcm_dialog_type end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 575 def fedcm_subtitle execute(:get_fedcm_title).fetch('subtitle', nil) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 571 def fedcm_title execute(:get_fedcm_title).fetch('title') end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 481 def find_element_by(how, what, parent_ref = []) how, what = @locator_converter.convert(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 Bridge.element_class.new self, element_id_from(id) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 499 def find_elements_by(how, what, parent_ref = []) how, what = @locator_converter.convert(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| Bridge.element_class.new self, element_id_from(id) } end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 267 def full_screen_window execute :fullscreen_window end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 118 def get(url) execute :get, {}, {url: url} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 158 def go_back execute :back end
navigation
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 162 def go_forward execute :forward end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 317 def manage @manage ||= WebDriver::Manager.new(self) end
cookies
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 258 def maximize_window(handle = :current) unless handle == :current raise Error::UnsupportedOperationError, 'Switch to desired window before changing its size' end execute :maximize_window end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 254 def minimize_window execute :minimize_window end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 188 def new_window(type) execute :new_window, {}, {type: type} end
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
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 174 def page_source execute :get_page_source end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 360 def print_page(options = {}) execute :print_page, {}, {options: options} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 211 def quit execute :delete_session http.close rescue *QUIT_ERRORS nil end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 222 def refresh execute :refresh end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 356 def release_actions execute :release_actions end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 547 def remove_all_credentials(authenticator_id) execute :remove_all_credentials, {authenticatorId: authenticator_id} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 543 def remove_credential(credential_id, authenticator_id) execute :remove_credential, {credentialId: credential_id, authenticatorId: authenticator_id} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 531 def remove_virtual_authenticator(id) execute :remove_virtual_authenticator, {authenticatorId: id} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 271 def reposition_window(x, y) set_window_rect(x: x, y: y) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 587 def reset_fedcm_cooldown execute :reset_fedcm_cooldown end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 238 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
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 291 def screenshot execute :take_screenshot end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 563 def select_fedcm_account(index) execute :select_fedcm_account, {}, {accountIndex: index} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 352 def send_actions(data) execute :actions, {}, {actions: data} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 368 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
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 103 def session_id @session_id || raise(Error::WebDriverError, 'no current session exists') end
Returns the current session ID.
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 280 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
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 517 def shadow_root(element) id = execute :get_element_shadow_root, id: element ShadowRoot.new self, shadow_root_id_from(id) end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 114 def status execute :status end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 378 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, Bridge.element_class::ELEMENT_KEY => element) rescue Error::JavascriptError raise Error::UnsupportedOperationError, 'To submit an element, it must be nested inside a form element' end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 205 def switch_to_default_content switch_to_frame nil end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 196 def switch_to_frame(id) id = find_element_by('id', id) if id.is_a? String execute :switch_to_frame, {}, {id: id} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 201 def switch_to_parent_frame execute :switch_to_parent_frame end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 192 def switch_to_window(name) execute :switch_to_window, {}, {handle: name} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 126 def timeouts execute :get_timeouts, {} end
timeouts
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 130 def timeouts=(timeouts) execute :set_timeout, {}, timeouts end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 170 def title execute :get_title end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 166 def url execute :get_current_url end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 551 def user_verified(verified, authenticator_id) execute :set_user_verified, {authenticatorId: authenticator_id}, {isUserVerified: verified} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 234 def window_handle execute :get_window_handle end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 230 def window_handles execute :get_window_handles end
window handling
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 275 def window_position data = execute :get_window_rect Point.new data['x'], data['y'] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 286 def window_rect data = execute :get_window_rect Rectangle.new data['x'], data['y'], data['width'], data['height'] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 244 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
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 632 def commands(command) command_list[command] || Bridge.extra_commands[command] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 653 def element_id_from(id) id['ELEMENT'] || id[Bridge.element_class::ELEMENT_KEY] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 628 def escaper @escaper ||= defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 612 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
executes a command on the remote server.
@return [WebDriver::Remote::Response]
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 661 def prepare_capabilities_payload(capabilities) capabilities = {alwaysMatch: capabilities} if !capabilities['alwaysMatch'] && !capabilities['firstMatch'] {capabilities: capabilities} end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 657 def shadow_root_id_from(id) id[ShadowRoot::ROOT_KEY] end
Source
# File lib/selenium/webdriver/remote/bridge.rb, line 636 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 Bridge.element_class.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