Class: Selenium::WebDriver::Remote::Bridge Private
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Remote::Bridge
- Includes:
- Atoms
- Defined in:
- lib/selenium/webdriver/remote/commands.rb,
lib/selenium/webdriver/remote/bridge.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- PORT =
4444
- QUIT_ERRORS =
[IOError].freeze
- COMMANDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 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'], # # server extensions # upload_file: [:post, 'session/:session_id/se/file'] }.freeze
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#file_detector ⇒ Object
Returns the value of attribute file_detector.
-
#http ⇒ Object
Returns the value of attribute http.
Instance Method Summary collapse
-
#accept_alert ⇒ Object
alerts.
-
#action(deprecated_async = nil, async: false, devices: [], duration: 250) ⇒ Object
(also: #actions)
actions.
-
#active_element ⇒ Object
(also: #switch_to_active_element)
finding elements.
- #add_cookie(cookie) ⇒ Object
- #alert=(keys) ⇒ Object
- #alert_text ⇒ Object
- #browser ⇒ Object
- #clear_element(element) ⇒ Object
- #clear_local_storage ⇒ Object
- #clear_session_storage ⇒ Object
- #click_element(element) ⇒ Object
- #close ⇒ Object
- #cookie(name) ⇒ Object
- #cookies ⇒ Object
-
#create_session(capabilities) ⇒ Object
Creates session.
- #delete_all_cookies ⇒ Object
- #delete_cookie(name) ⇒ Object
- #dismiss_alert ⇒ Object
- #element_aria_label(element) ⇒ Object
- #element_aria_role(element) ⇒ Object
- #element_attribute(element, name) ⇒ Object
- #element_displayed?(element) ⇒ Boolean
- #element_dom_attribute(element, name) ⇒ Object
- #element_enabled?(element) ⇒ Boolean
- #element_location(element) ⇒ Object
- #element_location_once_scrolled_into_view(element) ⇒ Object
- #element_property(element, name) ⇒ Object
- #element_rect(element) ⇒ Object
- #element_screenshot(element) ⇒ Object
- #element_selected?(element) ⇒ Boolean
- #element_size(element) ⇒ Object
-
#element_tag_name(element) ⇒ Object
element properties.
- #element_text(element) ⇒ Object
- #element_value(element) ⇒ Object
- #element_value_of_css_property(element, prop) ⇒ Object
- #execute_async_script(script, *args) ⇒ Object
-
#execute_script(script, *args) ⇒ Object
javascript execution.
- #find_element_by(how, what, parent_ref = []) ⇒ Object
- #find_elements_by(how, what, parent_ref = []) ⇒ Object
- #full_screen_window ⇒ Object
- #get(url) ⇒ Object
-
#go_back ⇒ Object
navigation.
- #go_forward ⇒ Object
-
#initialize(url:, http_client: nil) ⇒ Bridge
constructor
private
Initializes the bridge with the given server URL.
- #keyboard ⇒ Object
-
#local_storage_item(key, value = nil) ⇒ Object
HTML 5.
- #local_storage_keys ⇒ Object
- #local_storage_size ⇒ Object
-
#manage ⇒ Object
cookies.
- #maximize_window(handle = :current) ⇒ Object
- #minimize_window ⇒ Object
- #mouse ⇒ Object
-
#new_window(type) ⇒ Hash
Create a new top-level browsing context w3c.github.io/webdriver/#new-window.
- #page_source ⇒ Object
- #print_page(options = {}) ⇒ Object
- #quit ⇒ Object
- #refresh ⇒ Object
- #release_actions ⇒ Object
- #remove_local_storage_item(key) ⇒ Object
- #remove_session_storage_item(key) ⇒ Object
- #reposition_window(x, y) ⇒ Object
- #resize_window(width, height, handle = :current) ⇒ Object
- #screenshot ⇒ Object
- #send_actions(data) ⇒ Object
- #send_keys_to_element(element, keys) ⇒ Object
-
#session_id ⇒ Object
Returns the current session ID.
- #session_storage_item(key, value = nil) ⇒ Object
- #session_storage_keys ⇒ Object
- #session_storage_size ⇒ Object
- #set_window_rect(x: nil, y: nil, width: nil, height: nil) ⇒ Object
- #shadow_root(element) ⇒ Object
- #status ⇒ Object
- #submit_element(element) ⇒ Object
- #switch_to_default_content ⇒ Object
- #switch_to_frame(id) ⇒ Object
- #switch_to_parent_frame ⇒ Object
- #switch_to_window(name) ⇒ Object
-
#timeouts ⇒ Object
timeouts.
- #timeouts=(timeouts) ⇒ Object
- #title ⇒ Object
- #upload(local_file) ⇒ Object
- #url ⇒ Object
- #window_handle ⇒ Object
-
#window_handles ⇒ Object
window handling.
- #window_position ⇒ Object
- #window_rect ⇒ Object
- #window_size(handle = :current) ⇒ Object
Constructor Details
#initialize(url:, http_client: nil) ⇒ Bridge
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the bridge with the given server URL
38 39 40 41 42 43 44 45 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 38 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
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
29 30 31 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 29 def capabilities @capabilities end |
#file_detector ⇒ Object
Returns the value of attribute file_detector.
28 29 30 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 28 def file_detector @file_detector end |
#http ⇒ Object
Returns the value of attribute http.
28 29 30 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 28 def http @http end |
Instance Method Details
#accept_alert ⇒ Object
alerts
112 113 114 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 112 def accept_alert execute :accept_alert end |
#action(deprecated_async = nil, async: false, devices: [], duration: 250) ⇒ Object Also known as: actions
actions
370 371 372 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 370 def action(deprecated_async = nil, async: false, devices: [], duration: 250) ActionBuilder.new self, nil, nil, deprecated_async, async: async, devices: devices, duration: duration end |
#active_element ⇒ Object Also known as: switch_to_active_element
finding elements
524 525 526 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 524 def active_element Element.new self, element_id_from(execute(:get_active_element)) end |
#add_cookie(cookie) ⇒ Object
346 347 348 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 346 def () execute :add_cookie, {}, {cookie: } end |
#alert=(keys) ⇒ Object
120 121 122 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 120 def alert=(keys) execute :send_alert_text, {}, {value: keys.chars, text: keys} end |
#alert_text ⇒ Object
124 125 126 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 124 def alert_text execute :get_alert_text end |
#browser ⇒ Object
81 82 83 84 85 86 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 81 def browser @browser ||= begin name = @capabilities.browser_name name ? name.tr(' ', '_').downcase.to_sym : 'unknown' end end |
#clear_element(element) ⇒ Object
423 424 425 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 423 def clear_element(element) execute :element_clear, id: element end |
#clear_local_storage ⇒ Object
292 293 294 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 292 def clear_local_storage execute_script('localStorage.clear()') end |
#clear_session_storage ⇒ Object
316 317 318 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 316 def clear_session_storage execute_script('sessionStorage.clear()') end |
#click_element(element) ⇒ Object
395 396 397 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 395 def click_element(element) execute :element_click, id: element end |
#close ⇒ Object
191 192 193 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 191 def close execute :close_window end |
#cookie(name) ⇒ Object
354 355 356 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 354 def (name) execute :get_cookie, name: name end |
#cookies ⇒ Object
358 359 360 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 358 def execute :get_all_cookies end |
#create_session(capabilities) ⇒ Object
Creates session.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 51 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' extend(WebDriver::Chrome::Features) when 'firefox' extend(WebDriver::Firefox::Features) when 'msedge' extend(WebDriver::Edge::Features) when 'Safari', 'Safari Technology Preview' extend(WebDriver::Safari::Features) end end |
#delete_all_cookies ⇒ Object
362 363 364 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 362 def execute :delete_all_cookies end |
#delete_cookie(name) ⇒ Object
350 351 352 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 350 def (name) execute :delete_cookie, name: name end |
#dismiss_alert ⇒ Object
116 117 118 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 116 def dismiss_alert execute :dismiss_alert end |
#element_aria_label(element) ⇒ Object
468 469 470 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 468 def element_aria_label(element) execute :get_element_aria_label, id: element end |
#element_aria_role(element) ⇒ Object
464 465 466 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 464 def element_aria_role(element) execute :get_element_aria_role, id: element end |
#element_attribute(element, name) ⇒ Object
451 452 453 454 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 451 def element_attribute(element, name) WebDriver.logger.info "Using script for :getAttribute of #{name}" execute_atom :getAttribute, element, name end |
#element_displayed?(element) ⇒ Boolean
511 512 513 514 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 511 def element_displayed?(element) WebDriver.logger.info 'Using script for :isDisplayed' execute_atom :isDisplayed, element end |
#element_dom_attribute(element, name) ⇒ Object
456 457 458 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 456 def element_dom_attribute(element, name) execute :get_element_attribute, id: element, name: name end |
#element_enabled?(element) ⇒ Boolean
503 504 505 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 503 def element_enabled?(element) execute :is_element_enabled, id: element end |
#element_location(element) ⇒ Object
480 481 482 483 484 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 480 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) ⇒ Object
492 493 494 495 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 492 def element_location_once_scrolled_into_view(element) send_keys_to_element(element, ['']) element_location(element) end |
#element_property(element, name) ⇒ Object
460 461 462 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 460 def element_property(element, name) execute :get_element_property, id: element, name: name end |
#element_rect(element) ⇒ Object
486 487 488 489 490 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 486 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) ⇒ Object
268 269 270 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 268 def element_screenshot(element) execute :take_element_screenshot, id: element end |
#element_selected?(element) ⇒ Boolean
507 508 509 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 507 def element_selected?(element) execute :is_element_selected, id: element end |
#element_size(element) ⇒ Object
497 498 499 500 501 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 497 def element_size(element) data = execute :get_element_rect, id: element Dimension.new data['width'], data['height'] end |
#element_tag_name(element) ⇒ Object
element properties
447 448 449 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 447 def element_tag_name(element) execute :get_element_tag_name, id: element end |
#element_text(element) ⇒ Object
476 477 478 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 476 def element_text(element) execute :get_element_text, id: element end |
#element_value(element) ⇒ Object
472 473 474 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 472 def element_value(element) element_property element, 'value' end |
#element_value_of_css_property(element, prop) ⇒ Object
516 517 518 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 516 def element_value_of_css_property(element, prop) execute :get_element_css_value, id: element, property_name: prop end |
#execute_async_script(script, *args) ⇒ Object
333 334 335 336 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 333 def execute_async_script(script, *args) result = execute :execute_async_script, {}, {script: script, args: args} unwrap_script_result result end |
#execute_script(script, *args) ⇒ Object
javascript execution
328 329 330 331 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 328 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 = []) ⇒ Object
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 530 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 = []) ⇒ Object
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 548 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 ⇒ Object
240 241 242 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 240 def full_screen_window execute :fullscreen_window end |
#get(url) ⇒ Object
92 93 94 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 92 def get(url) execute :get, {}, {url: url} end |
#go_back ⇒ Object
navigation
132 133 134 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 132 def go_back execute :back end |
#go_forward ⇒ Object
136 137 138 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 136 def go_forward execute :forward end |
#keyboard ⇒ Object
379 380 381 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 379 def keyboard raise Error::UnsupportedOperationError, '#keyboard is no longer supported, use #action instead' end |
#local_storage_item(key, value = nil) ⇒ Object
HTML 5
276 277 278 279 280 281 282 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 276 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 ⇒ Object
288 289 290 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 288 def local_storage_keys execute_script('return Object.keys(localStorage)') end |
#local_storage_size ⇒ Object
296 297 298 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 296 def local_storage_size execute_script('return localStorage.length') end |
#manage ⇒ Object
cookies
342 343 344 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 342 def manage @manage ||= WebDriver::Manager.new(self) end |
#maximize_window(handle = :current) ⇒ Object
231 232 233 234 235 236 237 238 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 231 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 ⇒ Object
227 228 229 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 227 def minimize_window execute :minimize_window end |
#mouse ⇒ Object
375 376 377 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 375 def mouse raise Error::UnsupportedOperationError, '#mouse is no longer supported, use #action instead' end |
#new_window(type) ⇒ Hash
Create a new top-level browsing context w3c.github.io/webdriver/#new-window
162 163 164 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 162 def new_window(type) execute :new_window, {}, {type: type} end |
#page_source ⇒ Object
148 149 150 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 148 def page_source execute :get_page_source end |
#print_page(options = {}) ⇒ Object
391 392 393 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 391 def print_page( = {}) execute :print_page, {}, {options: } end |
#quit ⇒ Object
185 186 187 188 189 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 185 def quit execute :delete_session http.close rescue *QUIT_ERRORS end |
#refresh ⇒ Object
195 196 197 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 195 def refresh execute :refresh end |
#release_actions ⇒ Object
387 388 389 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 387 def release_actions execute :release_actions end |
#remove_local_storage_item(key) ⇒ Object
284 285 286 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 284 def remove_local_storage_item(key) execute_script("localStorage.removeItem('#{key}')") end |
#remove_session_storage_item(key) ⇒ Object
308 309 310 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 308 def remove_session_storage_item(key) execute_script("sessionStorage.removeItem('#{key}')") end |
#reposition_window(x, y) ⇒ Object
244 245 246 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 244 def reposition_window(x, y) set_window_rect(x: x, y: y) end |
#resize_window(width, height, handle = :current) ⇒ Object
211 212 213 214 215 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 211 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 ⇒ Object
264 265 266 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 264 def screenshot execute :take_screenshot end |
#send_actions(data) ⇒ Object
383 384 385 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 383 def send_actions(data) execute :actions, {}, {actions: data} end |
#send_keys_to_element(element, keys) ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 399 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.chars, text: text} end |
#session_id ⇒ Object
Returns the current session ID.
77 78 79 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 77 def session_id @session_id || raise(Error::WebDriverError, 'no current session exists') end |
#session_storage_item(key, value = nil) ⇒ Object
300 301 302 303 304 305 306 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 300 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 ⇒ Object
312 313 314 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 312 def session_storage_keys execute_script('return Object.keys(sessionStorage)') end |
#session_storage_size ⇒ Object
320 321 322 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 320 def session_storage_size execute_script('return sessionStorage.length') end |
#set_window_rect(x: nil, y: nil, width: nil, height: nil) ⇒ Object
253 254 255 256 257 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 253 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) ⇒ Object
566 567 568 569 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 566 def shadow_root(element) id = execute :get_element_shadow_root, id: element ShadowRoot.new self, shadow_root_id_from(id) end |
#status ⇒ Object
88 89 90 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 88 def status execute :status end |
#submit_element(element) ⇒ Object
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 427 def submit_element(element) script = "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_default_content ⇒ Object
179 180 181 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 179 def switch_to_default_content switch_to_frame nil end |
#switch_to_frame(id) ⇒ Object
170 171 172 173 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 170 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 ⇒ Object
175 176 177 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 175 def switch_to_parent_frame execute :switch_to_parent_frame end |
#switch_to_window(name) ⇒ Object
166 167 168 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 166 def switch_to_window(name) execute :switch_to_window, {}, {handle: name} end |
#timeouts ⇒ Object
timeouts
100 101 102 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 100 def timeouts execute :get_timeouts, {} end |
#timeouts=(timeouts) ⇒ Object
104 105 106 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 104 def timeouts=(timeouts) execute :set_timeout, {}, timeouts end |
#title ⇒ Object
144 145 146 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 144 def title execute :get_title end |
#upload(local_file) ⇒ Object
414 415 416 417 418 419 420 421 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 414 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 ⇒ Object
140 141 142 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 140 def url execute :get_current_url end |
#window_handle ⇒ Object
207 208 209 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 207 def window_handle execute :get_window_handle end |
#window_handles ⇒ Object
window handling
203 204 205 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 203 def window_handles execute :get_window_handles end |
#window_position ⇒ Object
248 249 250 251 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 248 def window_position data = execute :get_window_rect Point.new data['x'], data['y'] end |
#window_rect ⇒ Object
259 260 261 262 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 259 def window_rect data = execute :get_window_rect Rectangle.new data['x'], data['y'], data['width'], data['height'] end |
#window_size(handle = :current) ⇒ Object
217 218 219 220 221 222 223 224 225 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 217 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 |