@@ -20,188 +20,119 @@ module WebDriver
20
20
module Error
21
21
22
22
#
23
- # Returns exception from code (Integer - OSS, String - W3C).
24
- # @param [Integer, String, nil] code
25
- #
26
-
27
- def self . for_code ( code )
28
- case code
29
- when nil , 0
30
- nil
31
- when Integer
32
- ERRORS . fetch ( code )
33
- when String
34
- klass_name = code . split ( ' ' ) . map ( &:capitalize ) . join . sub ( /Error$/ , '' )
35
- const_get ( "#{ klass_name } Error" , false )
36
- end
37
- rescue KeyError , NameError
23
+ # Returns exception from its string representation.
24
+ # @param [String, nil] error
25
+ #
26
+
27
+ def self . for_error ( error )
28
+ return if error . nil?
29
+
30
+ klass_name = error . split ( ' ' ) . map ( &:capitalize ) . join . sub ( /Error$/ , '' )
31
+ const_get ( "#{ klass_name } Error" , false )
32
+ rescue NameError
38
33
WebDriverError
39
34
end
40
35
41
36
class WebDriverError < StandardError ; end
42
37
43
- class IndexOutOfBoundsError < WebDriverError ; end # 1
44
- class NoCollectionError < WebDriverError ; end # 2
45
- class NoStringError < WebDriverError ; end # 3
46
- class NoStringLengthError < WebDriverError ; end # 4
47
- class NoStringWrapperError < WebDriverError ; end # 5
48
- class NoSuchDriverError < WebDriverError ; end # 6
49
-
50
38
#
51
39
# An element could not be located on the page using the given search parameters.
52
40
#
53
41
54
- class NoSuchElementError < WebDriverError ; end # 7
42
+ class NoSuchElementError < WebDriverError ; end
55
43
56
44
#
57
45
# A command to switch to a frame could not be satisfied because the frame could not be found.
58
46
#
59
47
60
- class NoSuchFrameError < WebDriverError ; end # 8
48
+ class NoSuchFrameError < WebDriverError ; end
61
49
62
50
#
63
51
# A command could not be executed because the remote end is not aware of it.
64
52
#
65
53
66
- class UnknownCommandError < WebDriverError ; end # 9
54
+ class UnknownCommandError < WebDriverError ; end
67
55
68
56
#
69
57
# A command failed because the referenced element is no longer attached to the DOM.
70
58
#
71
59
72
- class StaleElementReferenceError < WebDriverError ; end # 10
73
-
74
- #
75
- # Raised to indicate that although an element is present on the DOM, it is not visible, and
76
- # so is not able to be interacted with.
77
- #
78
-
79
- class ElementNotVisibleError < WebDriverError ; end # 11
60
+ class StaleElementReferenceError < WebDriverError ; end
80
61
81
62
#
82
63
# The target element is in an invalid state, rendering it impossible to interact with, for
83
64
# example if you click a disabled element.
84
65
#
85
66
86
- class InvalidElementStateError < WebDriverError ; end # 12
67
+ class InvalidElementStateError < WebDriverError ; end
87
68
88
69
#
89
70
# An unknown error occurred in the remote end while processing the command.
90
71
#
91
72
92
- class UnknownError < WebDriverError ; end # 13
93
- class ExpectedError < WebDriverError ; end # 14
94
-
95
- #
96
- # An attempt was made to select an element that cannot be selected.
97
- #
98
-
99
- class ElementNotSelectableError < WebDriverError ; end # 15
100
- class NoSuchDocumentError < WebDriverError ; end # 16
73
+ class UnknownError < WebDriverError ; end
101
74
102
75
#
103
76
# An error occurred while executing JavaScript supplied by the user.
104
77
#
105
78
106
- class JavascriptError < WebDriverError ; end # 17
107
- class NoScriptResultError < WebDriverError ; end # 18
79
+ class JavascriptError < WebDriverError ; end
108
80
109
81
#
110
- # An error occurred while searching for an element by XPath .
82
+ # An operation did not complete before its timeout expired .
111
83
#
112
84
113
- class XPathLookupError < WebDriverError ; end # 19
114
- class NoSuchCollectionError < WebDriverError ; end # 20
85
+ class TimeOutError < WebDriverError ; end
115
86
116
87
#
117
- # An operation did not complete before its timeout expired.
88
+ # A command to switch to a window could not be satisfied because
89
+ # the window could not be found.
118
90
#
119
91
120
- class TimeOutError < WebDriverError ; end # 21
121
-
122
- class NullPointerError < WebDriverError ; end # 22
123
- class NoSuchWindowError < WebDriverError ; end # 23
92
+ class NoSuchWindowError < WebDriverError ; end
124
93
125
94
#
126
95
# An illegal attempt was made to set a cookie under a different domain than the current page.
127
96
#
128
97
129
- class InvalidCookieDomainError < WebDriverError ; end # 24
98
+ class InvalidCookieDomainError < WebDriverError ; end
130
99
131
100
#
132
101
# A command to set a cookie's value could not be satisfied.
133
102
#
134
103
135
- class UnableToSetCookieError < WebDriverError ; end # 25
136
-
137
- #
138
- # Raised when an alert dialog is present that has not been dealt with.
139
- #
140
- class UnhandledAlertError < WebDriverError ; end # 26
104
+ class UnableToSetCookieError < WebDriverError ; end
141
105
142
106
#
143
107
# An attempt was made to operate on a modal dialog when one was not open:
144
108
#
145
- # * W3C dialect is NoSuchAlertError
146
- # * OSS dialect is NoAlertPresentError
147
- #
148
- # We want to allow clients to rescue NoSuchAlertError as a superclass for
149
- # dialect-agnostic implementation, so NoAlertPresentError should inherit from it.
150
- #
151
109
152
110
class NoSuchAlertError < WebDriverError ; end
153
- class NoAlertPresentError < NoSuchAlertError ; end # 27
154
111
155
112
#
156
113
# A script did not complete before its timeout expired.
157
114
#
158
115
159
- class ScriptTimeOutError < WebDriverError ; end # 28
160
-
161
- #
162
- # The coordinates provided to an interactions operation are invalid.
163
- #
164
-
165
- class InvalidElementCoordinatesError < WebDriverError ; end # 29
166
-
167
- #
168
- # Indicates that IME support is not available. This exception is rasied for every IME-related
169
- # method call if IME support is not available on the machine.
170
- #
171
-
172
- class IMENotAvailableError < WebDriverError ; end # 30
173
-
174
- #
175
- # Indicates that activating an IME engine has failed.
176
- #
177
-
178
- class IMEEngineActivationFailedError < WebDriverError ; end # 31
116
+ class ScriptTimeoutError < WebDriverError ; end
179
117
180
118
#
181
119
# Argument was an invalid selector.
182
120
#
183
121
184
- class InvalidSelectorError < WebDriverError ; end # 32
122
+ class InvalidSelectorError < WebDriverError ; end
185
123
186
124
#
187
125
# A new session could not be created.
188
126
#
189
127
190
- class SessionNotCreatedError < WebDriverError ; end # 33
128
+ class SessionNotCreatedError < WebDriverError ; end
191
129
192
130
#
193
131
# The target for mouse interaction is not in the browser's viewport and cannot be brought
194
132
# into that viewport.
195
133
#
196
134
197
- class MoveTargetOutOfBoundsError < WebDriverError ; end # 34
198
-
199
- #
200
- # Indicates that the XPath selector is invalid
201
- #
202
-
203
- class InvalidXpathSelectorError < WebDriverError ; end
204
- class InvalidXpathSelectorReturnTyperError < WebDriverError ; end
135
+ class MoveTargetOutOfBoundsError < WebDriverError ; end
205
136
206
137
#
207
138
# A command could not be completed because the element is not pointer or keyboard
@@ -269,66 +200,6 @@ class ElementClickInterceptedError < WebDriverError; end
269
200
270
201
class UnsupportedOperationError < WebDriverError ; end
271
202
272
- # Aliases for OSS dialect.
273
- ScriptTimeoutError = ScriptTimeOutError
274
- TimeoutError = TimeOutError
275
- NoAlertOpenError = NoAlertPresentError
276
-
277
- # Aliases for backwards compatibility.
278
- ObsoleteElementError = StaleElementReferenceError
279
- UnhandledError = UnknownError
280
- UnexpectedJavascriptError = JavascriptError
281
- ElementNotDisplayedError = ElementNotVisibleError
282
-
283
- #
284
- # @api private
285
- #
286
-
287
- ERRORS = {
288
- 1 => IndexOutOfBoundsError ,
289
- 2 => NoCollectionError ,
290
- 3 => NoStringError ,
291
- 4 => NoStringLengthError ,
292
- 5 => NoStringWrapperError ,
293
- 6 => NoSuchDriverError ,
294
- 7 => NoSuchElementError ,
295
- 8 => NoSuchFrameError ,
296
- 9 => UnknownCommandError ,
297
- 10 => StaleElementReferenceError ,
298
- 11 => ElementNotVisibleError ,
299
- 12 => InvalidElementStateError ,
300
- 13 => UnknownError ,
301
- 14 => ExpectedError ,
302
- 15 => ElementNotSelectableError ,
303
- 16 => NoSuchDocumentError ,
304
- 17 => JavascriptError ,
305
- 18 => NoScriptResultError ,
306
- 19 => XPathLookupError ,
307
- 20 => NoSuchCollectionError ,
308
- 21 => TimeOutError ,
309
- 22 => NullPointerError ,
310
- 23 => NoSuchWindowError ,
311
- 24 => InvalidCookieDomainError ,
312
- 25 => UnableToSetCookieError ,
313
- 26 => UnhandledAlertError ,
314
- 27 => NoAlertPresentError ,
315
- 28 => ScriptTimeOutError ,
316
- 29 => InvalidElementCoordinatesError ,
317
- 30 => IMENotAvailableError ,
318
- 31 => IMEEngineActivationFailedError ,
319
- 32 => InvalidSelectorError ,
320
- 33 => SessionNotCreatedError ,
321
- 34 => MoveTargetOutOfBoundsError ,
322
- # The following are W3C-specific errors,
323
- # they don't really need error codes, we just make them up!
324
- 51 => InvalidXpathSelectorError ,
325
- 52 => InvalidXpathSelectorReturnTyperError ,
326
- 60 => ElementNotInteractableError ,
327
- 61 => InvalidArgumentError ,
328
- 62 => NoSuchCookieError ,
329
- 63 => UnableToCaptureScreenError
330
- } . freeze
331
-
332
203
end # Error
333
204
end # WebDriver
334
205
end # Selenium
0 commit comments