selenium-webdriver 3.142.7 → 4.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +685 -5
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/NOTICE +2 -0
  6. data/README.md +4 -5
  7. data/bin/linux/selenium-manager +0 -0
  8. data/bin/macos/selenium-manager +0 -0
  9. data/bin/windows/selenium-manager.exe +0 -0
  10. data/lib/selenium/server.rb +93 -90
  11. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  12. data/lib/selenium/webdriver/atoms/getAttribute.js +100 -7
  13. data/lib/selenium/webdriver/atoms/isDisplayed.js +77 -78
  14. data/lib/selenium/webdriver/atoms/mutationListener.js +55 -0
  15. data/lib/selenium/webdriver/atoms.rb +5 -3
  16. data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
  17. data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
  18. data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
  19. data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
  20. data/lib/selenium/webdriver/bidi/log/filter_by.rb +40 -0
  21. data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
  22. data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
  23. data/lib/selenium/webdriver/bidi/log_inspector.rb +143 -0
  24. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  25. data/lib/selenium/webdriver/bidi/session.rb +51 -0
  26. data/lib/selenium/webdriver/{common/keyboard.rb → bidi.rb} +21 -35
  27. data/lib/selenium/webdriver/chrome/driver.rb +9 -86
  28. data/lib/selenium/webdriver/chrome/features.rb +48 -0
  29. data/lib/selenium/webdriver/chrome/options.rb +9 -158
  30. data/lib/selenium/webdriver/chrome/profile.rb +3 -80
  31. data/lib/selenium/webdriver/chrome/service.rb +7 -29
  32. data/lib/selenium/webdriver/chrome.rb +5 -20
  33. data/lib/selenium/webdriver/chromium/driver.rb +60 -0
  34. data/lib/selenium/webdriver/{chrome/bridge.rb → chromium/features.rb} +48 -17
  35. data/lib/selenium/webdriver/chromium/options.rb +243 -0
  36. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  37. data/lib/selenium/webdriver/chromium.rb +29 -0
  38. data/lib/selenium/webdriver/common/action_builder.rb +126 -238
  39. data/lib/selenium/webdriver/common/child_process.rb +124 -0
  40. data/lib/selenium/webdriver/common/driver.rb +82 -43
  41. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  42. data/lib/selenium/webdriver/common/driver_extensions/{has_location.rb → full_page_screenshot.rb} +13 -11
  43. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +49 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +87 -0
  46. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_bidi.rb} +9 -9
  47. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +86 -0
  48. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +36 -0
  49. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +42 -0
  50. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  51. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +41 -0
  52. data/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb +65 -0
  53. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +36 -0
  54. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
  55. data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_logs.rb} +4 -4
  56. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +16 -1
  57. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +69 -0
  58. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -13
  59. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +75 -0
  60. data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
  61. data/lib/selenium/webdriver/common/driver_finder.rb +45 -0
  62. data/lib/selenium/webdriver/common/element.rb +89 -29
  63. data/lib/selenium/webdriver/common/error.rb +53 -194
  64. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  65. data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
  66. data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -22
  67. data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
  68. data/lib/selenium/webdriver/common/interactions/key_actions.rb +10 -6
  69. data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
  70. data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
  71. data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
  72. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +71 -82
  73. data/lib/selenium/webdriver/common/interactions/pointer_cancel.rb +45 -0
  74. data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
  75. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
  76. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
  77. data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
  78. data/lib/selenium/webdriver/common/interactions/scroll.rb +59 -0
  79. data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
  80. data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
  81. data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +113 -0
  82. data/lib/selenium/webdriver/common/{w3c_manager.rb → interactions/wheel_input.rb} +14 -17
  83. data/lib/selenium/webdriver/common/keys.rb +1 -0
  84. data/lib/selenium/webdriver/common/local_driver.rb +46 -0
  85. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  86. data/lib/selenium/webdriver/common/logger.rb +119 -19
  87. data/lib/selenium/webdriver/common/manager.rb +11 -38
  88. data/lib/selenium/webdriver/common/options.rb +154 -23
  89. data/lib/selenium/webdriver/common/platform.rb +15 -52
  90. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  91. data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
  92. data/lib/selenium/webdriver/common/proxy.rb +8 -5
  93. data/lib/selenium/webdriver/common/search_context.rb +7 -9
  94. data/lib/selenium/webdriver/common/selenium_manager.rb +140 -0
  95. data/lib/selenium/webdriver/common/service.rb +26 -143
  96. data/lib/selenium/webdriver/common/service_manager.rb +144 -0
  97. data/lib/selenium/webdriver/common/shadow_root.rb +86 -0
  98. data/lib/selenium/webdriver/common/socket_lock.rb +4 -4
  99. data/lib/selenium/webdriver/common/socket_poller.rb +4 -4
  100. data/lib/selenium/webdriver/common/takes_screenshot.rb +65 -0
  101. data/lib/selenium/webdriver/common/target_locator.rb +31 -4
  102. data/lib/selenium/webdriver/common/timeouts.rb +31 -4
  103. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +85 -0
  104. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +72 -0
  105. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +62 -0
  106. data/lib/selenium/webdriver/common/wait.rb +1 -1
  107. data/lib/selenium/webdriver/common/websocket_connection.rb +164 -0
  108. data/lib/selenium/webdriver/common/window.rb +6 -10
  109. data/lib/selenium/webdriver/common/zipper.rb +4 -10
  110. data/lib/selenium/webdriver/common.rb +43 -20
  111. data/lib/selenium/webdriver/devtools/console_event.rb +36 -0
  112. data/lib/selenium/webdriver/devtools/exception_event.rb +34 -0
  113. data/lib/selenium/webdriver/devtools/mutation_event.rb +35 -0
  114. data/lib/selenium/webdriver/devtools/network_interceptor.rb +173 -0
  115. data/lib/selenium/webdriver/devtools/pinned_script.rb +57 -0
  116. data/lib/selenium/webdriver/devtools/request.rb +65 -0
  117. data/lib/selenium/webdriver/devtools/response.rb +64 -0
  118. data/lib/selenium/webdriver/devtools.rb +96 -0
  119. data/lib/selenium/webdriver/edge/driver.rb +11 -27
  120. data/lib/selenium/webdriver/edge/features.rb +48 -0
  121. data/lib/selenium/webdriver/edge/options.rb +18 -43
  122. data/lib/selenium/webdriver/edge/profile.rb +33 -0
  123. data/lib/selenium/webdriver/edge/service.rb +8 -23
  124. data/lib/selenium/webdriver/edge.rb +11 -16
  125. data/lib/selenium/webdriver/firefox/driver.rb +38 -19
  126. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  127. data/lib/selenium/webdriver/firefox/features.rb +70 -0
  128. data/lib/selenium/webdriver/firefox/options.rb +73 -61
  129. data/lib/selenium/webdriver/firefox/profile.rb +20 -72
  130. data/lib/selenium/webdriver/firefox/service.rb +3 -25
  131. data/lib/selenium/webdriver/firefox/util.rb +1 -1
  132. data/lib/selenium/webdriver/firefox.rb +17 -28
  133. data/lib/selenium/webdriver/ie/driver.rb +5 -45
  134. data/lib/selenium/webdriver/ie/features.rb +34 -0
  135. data/lib/selenium/webdriver/ie/options.rb +14 -44
  136. data/lib/selenium/webdriver/ie/service.rb +3 -27
  137. data/lib/selenium/webdriver/ie.rb +4 -16
  138. data/lib/selenium/webdriver/remote/bridge/commands.rb +164 -0
  139. data/lib/selenium/webdriver/remote/bridge.rb +574 -88
  140. data/lib/selenium/webdriver/remote/capabilities.rb +144 -158
  141. data/lib/selenium/webdriver/remote/driver.rb +45 -14
  142. data/lib/selenium/webdriver/remote/features.rb +75 -0
  143. data/lib/selenium/webdriver/remote/http/common.rb +3 -8
  144. data/lib/selenium/webdriver/remote/http/curb.rb +1 -3
  145. data/lib/selenium/webdriver/remote/http/default.rb +24 -33
  146. data/lib/selenium/webdriver/remote/response.rb +17 -49
  147. data/lib/selenium/webdriver/remote/server_error.rb +1 -1
  148. data/lib/selenium/webdriver/remote.rb +15 -12
  149. data/lib/selenium/webdriver/safari/driver.rb +7 -29
  150. data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +7 -5
  151. data/lib/selenium/webdriver/safari/options.rb +12 -27
  152. data/lib/selenium/webdriver/safari/service.rb +13 -11
  153. data/lib/selenium/webdriver/safari.rb +14 -20
  154. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
  155. data/lib/selenium/webdriver/support/color.rb +24 -24
  156. data/lib/selenium/webdriver/support/event_firing_bridge.rb +5 -5
  157. data/lib/selenium/webdriver/support/guards/guard.rb +90 -0
  158. data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +21 -20
  159. data/lib/selenium/webdriver/support/guards.rb +95 -0
  160. data/lib/selenium/webdriver/support/relative_locator.rb +50 -0
  161. data/lib/selenium/webdriver/support/select.rb +6 -4
  162. data/lib/selenium/webdriver/support.rb +1 -0
  163. data/lib/selenium/webdriver/version.rb +1 -1
  164. data/lib/selenium/webdriver.rb +19 -17
  165. data/selenium-webdriver.gemspec +36 -18
  166. metadata +161 -91
  167. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  168. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +0 -58
  169. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
  170. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  171. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  172. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  173. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  174. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  175. data/lib/selenium/webdriver/firefox/binary.rb +0 -187
  176. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  177. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  178. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  179. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  180. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  181. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  182. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  183. data/lib/selenium/webdriver/remote/http/persistent.rb +0 -60
  184. data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
  185. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  186. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  187. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  188. data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -1,594 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module WebDriver
22
- module Remote
23
- module OSS
24
-
25
- #
26
- # Low level bridge to the remote server implementing JSON wire
27
- # protocol (OSS dialect), through which the rest of the API works.
28
- # @api private
29
- #
30
-
31
- class Bridge < Remote::Bridge
32
-
33
- def initialize(capabilities, session_id, **opts)
34
- @capabilities = capabilities
35
- @session_id = session_id
36
- super(opts)
37
- end
38
-
39
- def dialect
40
- :oss
41
- end
42
-
43
- def commands(command)
44
- COMMANDS[command]
45
- end
46
-
47
- def status
48
- execute :status
49
- end
50
-
51
- def get(url)
52
- execute :get, {}, {url: url}
53
- end
54
-
55
- def session_capabilities
56
- Capabilities.json_create execute(:get_capabilities)
57
- end
58
-
59
- def implicit_wait_timeout=(milliseconds)
60
- execute :implicitly_wait, {}, {ms: milliseconds}
61
- end
62
-
63
- def script_timeout=(milliseconds)
64
- execute :set_script_timeout, {}, {ms: milliseconds}
65
- end
66
-
67
- def timeout(type, milliseconds)
68
- execute :set_timeout, {}, {type: type, ms: milliseconds}
69
- end
70
-
71
- #
72
- # alerts
73
- #
74
-
75
- def accept_alert
76
- execute :accept_alert
77
- end
78
-
79
- def dismiss_alert
80
- execute :dismiss_alert
81
- end
82
-
83
- def alert=(keys)
84
- execute :set_alert_value, {}, {text: keys.to_s}
85
- end
86
-
87
- def alert_text
88
- execute :get_alert_text
89
- end
90
-
91
- def authentication(credentials)
92
- execute :set_authentication, {}, credentials
93
- end
94
-
95
- #
96
- # navigation
97
- #
98
-
99
- def go_back
100
- execute :go_back
101
- end
102
-
103
- def go_forward
104
- execute :go_forward
105
- end
106
-
107
- def url
108
- execute :get_current_url
109
- end
110
-
111
- def title
112
- execute :get_title
113
- end
114
-
115
- def page_source
116
- execute :get_page_source
117
- end
118
-
119
- def switch_to_window(name)
120
- execute :switch_to_window, {}, {name: name}
121
- end
122
-
123
- def switch_to_frame(id)
124
- execute :switch_to_frame, {}, {id: id}
125
- end
126
-
127
- def switch_to_parent_frame
128
- execute :switch_to_parent_frame
129
- end
130
-
131
- def switch_to_default_content
132
- switch_to_frame(nil)
133
- end
134
-
135
- def quit
136
- execute :quit
137
- http.close
138
- rescue *http.quit_errors
139
- end
140
-
141
- def close
142
- execute :close
143
- end
144
-
145
- def refresh
146
- execute :refresh
147
- end
148
-
149
- #
150
- # window handling
151
- #
152
-
153
- def window_handles
154
- execute :get_window_handles
155
- end
156
-
157
- def window_handle
158
- execute :get_current_window_handle
159
- end
160
-
161
- def resize_window(width, height, handle = :current)
162
- execute :set_window_size, {window_handle: handle},
163
- {width: width,
164
- height: height}
165
- end
166
-
167
- def maximize_window(handle = :current)
168
- execute :maximize_window, window_handle: handle
169
- end
170
-
171
- def window_size(handle = :current)
172
- data = execute :get_window_size, window_handle: handle
173
-
174
- Dimension.new data['width'], data['height']
175
- end
176
-
177
- def reposition_window(x, y, handle = :current)
178
- execute :set_window_position, {window_handle: handle},
179
- {x: x, y: y}
180
- end
181
-
182
- def window_position(handle = :current)
183
- data = execute :get_window_position, window_handle: handle
184
-
185
- Point.new data['x'], data['y']
186
- end
187
-
188
- def screenshot
189
- execute :screenshot
190
- end
191
-
192
- #
193
- # HTML 5
194
- #
195
-
196
- def local_storage_item(key, value = nil)
197
- if value
198
- execute :set_local_storage_item, {}, {key: key, value: value}
199
- else
200
- execute :get_local_storage_item, key: key
201
- end
202
- end
203
-
204
- def remove_local_storage_item(key)
205
- execute :remove_local_storage_item, key: key
206
- end
207
-
208
- def local_storage_keys
209
- execute :get_local_storage_keys
210
- end
211
-
212
- def clear_local_storage
213
- execute :clear_local_storage
214
- end
215
-
216
- def local_storage_size
217
- execute :get_local_storage_size
218
- end
219
-
220
- def session_storage_item(key, value = nil)
221
- if value
222
- execute :set_session_storage_item, {}, {key: key, value: value}
223
- else
224
- execute :get_session_storage_item, key: key
225
- end
226
- end
227
-
228
- def remove_session_storage_item(key)
229
- execute :remove_session_storage_item, key: key
230
- end
231
-
232
- def session_storage_keys
233
- execute :get_session_storage_keys
234
- end
235
-
236
- def clear_session_storage
237
- execute :clear_session_storage
238
- end
239
-
240
- def session_storage_size
241
- execute :get_session_storage_size
242
- end
243
-
244
- def location
245
- obj = execute(:get_location) || {}
246
- Location.new obj['latitude'], obj['longitude'], obj['altitude']
247
- end
248
-
249
- def set_location(lat, lon, alt)
250
- loc = {latitude: lat, longitude: lon, altitude: alt}
251
- execute :set_location, {}, {location: loc}
252
- end
253
-
254
- def network_connection
255
- execute :get_network_connection
256
- end
257
-
258
- def network_connection=(type)
259
- execute :set_network_connection, {}, {parameters: {type: type}}
260
- end
261
-
262
- #
263
- # javascript execution
264
- #
265
-
266
- def execute_script(script, *args)
267
- assert_javascript_enabled
268
-
269
- result = execute :execute_script, {}, {script: script, args: args}
270
- unwrap_script_result result
271
- end
272
-
273
- def execute_async_script(script, *args)
274
- assert_javascript_enabled
275
-
276
- result = execute :execute_async_script, {}, {script: script, args: args}
277
- unwrap_script_result result
278
- end
279
-
280
- #
281
- # cookies
282
- #
283
-
284
- def manage
285
- @manage ||= WebDriver::Manager.new(self)
286
- end
287
-
288
- def add_cookie(cookie)
289
- execute :add_cookie, {}, {cookie: cookie}
290
- end
291
-
292
- def delete_cookie(name)
293
- execute :delete_cookie, name: name
294
- end
295
-
296
- def cookies
297
- execute :get_cookies
298
- end
299
-
300
- def delete_all_cookies
301
- execute :delete_all_cookies
302
- end
303
-
304
- #
305
- # actions
306
- #
307
-
308
- #
309
- # @return [ActionBuilder]
310
- # @api public
311
- #
312
-
313
- def action
314
- ActionBuilder.new Mouse.new(self), Keyboard.new(self)
315
- end
316
-
317
- def mouse
318
- WebDriver.logger.deprecate 'Driver#mouse', 'driver.action.<command>.perform'
319
- Mouse.new self
320
- end
321
-
322
- def keyboard
323
- WebDriver.logger.deprecate 'Driver#keyboard', 'driver.action.<command>.perform'
324
- Keyboard.new self
325
- end
326
-
327
- def click_element(element)
328
- execute :click_element, id: element
329
- end
330
-
331
- def click
332
- execute :click, {}, {button: 0}
333
- end
334
-
335
- def double_click
336
- execute :double_click
337
- end
338
-
339
- def context_click
340
- execute :click, {}, {button: 2}
341
- end
342
-
343
- def mouse_down
344
- execute :mouse_down
345
- end
346
-
347
- def mouse_up
348
- execute :mouse_up
349
- end
350
-
351
- def mouse_move_to(element, x = nil, y = nil)
352
- params = {element: element}
353
-
354
- if x && y
355
- params[:xoffset] = x
356
- params[:yoffset] = y
357
- end
358
-
359
- execute :mouse_move_to, {}, params
360
- end
361
-
362
- def send_keys_to_active_element(key)
363
- execute :send_keys_to_active_element, {}, {value: key}
364
- end
365
-
366
- def send_keys_to_element(element, keys)
367
- # TODO: rework file detectors before Selenium 4.0
368
- if @file_detector
369
- local_files = keys.first.split("\n").map { |key| @file_detector.call(Array(key)) }.compact
370
- if local_files.any?
371
- keys = local_files.map { |local_file| upload(local_file) }
372
- keys = keys.join("\n")
373
- end
374
- end
375
-
376
- execute :send_keys_to_element, {id: element}, {value: Array(keys)}
377
- end
378
-
379
- def upload(local_file)
380
- unless File.file?(local_file)
381
- WebDriver.logger.debug("File detector only works with files. #{local_file.inspect} isn`t a file!")
382
- raise Error::WebDriverError, "You are trying to work with something that isn't a file."
383
- end
384
-
385
- execute :upload_file, {}, {file: Zipper.zip_file(local_file)}
386
- end
387
-
388
- def clear_element(element)
389
- execute :clear_element, id: element
390
- end
391
-
392
- def submit_element(element)
393
- execute :submit_element, id: element
394
- end
395
-
396
- def drag_element(element, right_by, down_by)
397
- execute :drag_element, {id: element}, {x: right_by, y: down_by}
398
- end
399
-
400
- def touch_single_tap(element)
401
- execute :touch_single_tap, {}, {element: element}
402
- end
403
-
404
- def touch_double_tap(element)
405
- execute :touch_double_tap, {}, {element: element}
406
- end
407
-
408
- def touch_long_press(element)
409
- execute :touch_long_press, {}, {element: element}
410
- end
411
-
412
- def touch_down(x, y)
413
- execute :touch_down, {}, {x: x, y: y}
414
- end
415
-
416
- def touch_up(x, y)
417
- execute :touch_up, {}, {x: x, y: y}
418
- end
419
-
420
- def touch_move(x, y)
421
- execute :touch_move, {}, {x: x, y: y}
422
- end
423
-
424
- def touch_scroll(element, x, y)
425
- if element
426
- execute :touch_scroll, {}, {element: element,
427
- xoffset: x,
428
- yoffset: y}
429
- else
430
- execute :touch_scroll, {}, {xoffset: x, yoffset: y}
431
- end
432
- end
433
-
434
- def touch_flick(xspeed, yspeed)
435
- execute :touch_flick, {}, {xspeed: xspeed, yspeed: yspeed}
436
- end
437
-
438
- def touch_element_flick(element, right_by, down_by, speed)
439
- execute :touch_flick, {}, {element: element,
440
- xoffset: right_by,
441
- yoffset: down_by,
442
- speed: speed}
443
- end
444
-
445
- def screen_orientation=(orientation)
446
- execute :set_screen_orientation, {}, {orientation: orientation}
447
- end
448
-
449
- def screen_orientation
450
- execute :get_screen_orientation
451
- end
452
-
453
- #
454
- # logs
455
- #
456
-
457
- def available_log_types
458
- types = execute :get_available_log_types
459
- Array(types).map(&:to_sym)
460
- end
461
-
462
- def log(type)
463
- data = execute :get_log, {}, {type: type.to_s}
464
-
465
- Array(data).map do |l|
466
- begin
467
- LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
468
- rescue KeyError
469
- next
470
- end
471
- end
472
- end
473
-
474
- #
475
- # element properties
476
- #
477
-
478
- def element_tag_name(element)
479
- execute :get_element_tag_name, id: element
480
- end
481
-
482
- def element_attribute(element, name)
483
- execute :get_element_attribute, id: element.ref, name: name
484
- end
485
-
486
- # Backwards compatibility for w3c
487
- def element_property(element, name)
488
- execute_script 'return arguments[0][arguments[1]]', element, name
489
- end
490
-
491
- def element_value(element)
492
- execute :get_element_value, id: element
493
- end
494
-
495
- def element_text(element)
496
- execute :get_element_text, id: element
497
- end
498
-
499
- def element_location(element)
500
- data = execute :get_element_location, id: element
501
-
502
- Point.new data['x'], data['y']
503
- end
504
-
505
- def element_rect(element)
506
- loc = execute :get_element_location, id: element
507
- size = execute :get_element_size, id: element
508
-
509
- Rectangle.new loc['x'], loc['y'], size['width'], size['height']
510
- end
511
-
512
- def element_location_once_scrolled_into_view(element)
513
- data = execute :get_element_location_once_scrolled_into_view, id: element
514
-
515
- Point.new data['x'], data['y']
516
- end
517
-
518
- def element_size(element)
519
- data = execute :get_element_size, id: element
520
-
521
- Dimension.new data['width'], data['height']
522
- end
523
-
524
- def element_enabled?(element)
525
- execute :is_element_enabled, id: element
526
- end
527
-
528
- def element_selected?(element)
529
- execute :is_element_selected, id: element
530
- end
531
-
532
- def element_displayed?(element)
533
- execute :is_element_displayed, id: element.ref
534
- end
535
-
536
- def element_value_of_css_property(element, prop)
537
- execute :get_element_value_of_css_property, id: element, property_name: prop
538
- end
539
-
540
- #
541
- # finding elements
542
- #
543
-
544
- def active_element
545
- Element.new self, element_id_from(execute(:get_active_element))
546
- end
547
-
548
- alias_method :switch_to_active_element, :active_element
549
-
550
- def find_element_by(how, what, parent = nil)
551
- id = if parent
552
- execute :find_child_element, {id: parent}, {using: how, value: what}
553
- else
554
- execute :find_element, {}, {using: how, value: what}
555
- end
556
-
557
- Element.new self, element_id_from(id)
558
- end
559
-
560
- def find_elements_by(how, what, parent = nil)
561
- ids = if parent
562
- execute :find_child_elements, {id: parent}, {using: how, value: what}
563
- else
564
- execute :find_elements, {}, {using: how, value: what}
565
- end
566
- # see https://github.com/SeleniumHQ/selenium/issues/4555
567
- ids ||= []
568
-
569
- ids.map { |id| Element.new self, element_id_from(id) }
570
- end
571
-
572
- private
573
-
574
- def assert_javascript_enabled
575
- return if capabilities.javascript_enabled?
576
-
577
- raise Error::UnsupportedOperationError, 'underlying webdriver instance does not support javascript'
578
- end
579
-
580
- #
581
- # executes a command on the remote server.
582
- #
583
- # Returns the 'value' of the returned payload
584
- #
585
-
586
- def execute(*args)
587
- super['value']
588
- end
589
-
590
- end # Bridge
591
- end # OSS
592
- end # Remote
593
- end # WebDriver
594
- end # Selenium