Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/common/error.rb
1865 views
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 Error
23
#
24
# Returns exception from its string representation.
25
# @param [String, nil] error
26
#
27
28
def self.for_error(error)
29
return if error.nil?
30
31
klass_name = error.split.map(&:capitalize).join.sub(/Error$/, '')
32
const_get(:"#{klass_name}Error", false)
33
rescue NameError
34
WebDriverError
35
end
36
37
SUPPORT_MSG = 'For documentation on this error, please visit:'
38
ERROR_URL = 'https://www.selenium.dev/documentation/webdriver/troubleshooting/errors'
39
40
URLS = {
41
NoSuchElementError: "#{ERROR_URL}#no-such-element-exception",
42
StaleElementReferenceError: "#{ERROR_URL}#stale-element-reference-exception",
43
InvalidSelectorError: "#{ERROR_URL}#invalid-selector-exception",
44
NoSuchDriverError: "#{ERROR_URL}/driver_location"
45
}.freeze
46
47
class WebDriverError < StandardError
48
def initialize(msg = '')
49
# Remove this conditional when all the error pages have been documented
50
super(URLS[class_name] ? "#{msg}; #{SUPPORT_MSG} #{URLS[class_name]}" : msg)
51
end
52
53
# steep:ignore:start
54
def class_name
55
self.class.name.split('::')&.last&.to_sym
56
end
57
# steep:ignore:end
58
end
59
60
#
61
# An element could not be located on the page using the given search parameters.
62
#
63
64
class NoSuchElementError < WebDriverError; end
65
66
#
67
# A command to switch to a frame could not be satisfied because the frame could not be found.
68
#
69
70
class NoSuchFrameError < WebDriverError; end
71
72
#
73
# A command could not be executed because the remote end is not aware of it.
74
#
75
76
class UnknownCommandError < WebDriverError; end
77
78
#
79
# A command failed because the referenced element is no longer attached to the DOM.
80
#
81
82
class StaleElementReferenceError < WebDriverError; end
83
84
#
85
# A command failed because the referenced shadow root is no longer attached to the DOM.
86
#
87
88
class DetachedShadowRootError < WebDriverError; end
89
90
#
91
# The target element is in an invalid state, rendering it impossible to interact with, for
92
# example if you click a disabled element.
93
#
94
95
class InvalidElementStateError < WebDriverError; end
96
97
#
98
# An unknown error occurred in the remote end while processing the command.
99
#
100
101
class UnknownError < WebDriverError; end
102
103
#
104
# An error occurred while executing JavaScript supplied by the user.
105
#
106
107
class JavascriptError < WebDriverError; end
108
109
#
110
# An operation did not complete before its timeout expired.
111
#
112
113
class TimeoutError < WebDriverError; end
114
115
#
116
# A command to switch to a window could not be satisfied because
117
# the window could not be found.
118
#
119
120
class NoSuchWindowError < WebDriverError; end
121
122
#
123
# The element does not have a shadow root.
124
#
125
126
class NoSuchShadowRootError < WebDriverError; end
127
128
#
129
# An illegal attempt was made to set a cookie under a different domain than the current page.
130
#
131
132
class InvalidCookieDomainError < WebDriverError; end
133
134
#
135
# A command to set a cookie's value could not be satisfied.
136
#
137
138
class UnableToSetCookieError < WebDriverError; end
139
140
#
141
# An attempt was made to operate on a modal dialog when one was not open:
142
#
143
144
class NoSuchAlertError < WebDriverError; end
145
146
#
147
# A script did not complete before its timeout expired.
148
#
149
150
class ScriptTimeoutError < WebDriverError; end
151
152
#
153
# Argument was an invalid selector.
154
#
155
156
class InvalidSelectorError < WebDriverError; end
157
158
#
159
# A new session could not be created.
160
#
161
162
class SessionNotCreatedError < WebDriverError; end
163
164
#
165
# The target for mouse interaction is not in the browser's viewport and cannot be brought
166
# into that viewport.
167
#
168
169
class MoveTargetOutOfBoundsError < WebDriverError; end
170
171
#
172
# A command could not be completed because the element is not pointer or keyboard
173
# interactable.
174
#
175
176
class ElementNotInteractableError < WebDriverError; end
177
178
#
179
# A command could not be completed because TLS certificate is expired
180
# or invalid.
181
#
182
183
class InsecureCertificateError < WebDriverError; end
184
185
#
186
# The arguments passed to a command are either invalid or malformed.
187
#
188
189
class InvalidArgumentError < WebDriverError; end
190
191
#
192
# No cookie matching the given path name was found amongst the associated cookies of the
193
# current browsing context's active document.
194
#
195
196
class NoSuchCookieError < WebDriverError; end
197
198
#
199
# A screen capture was made impossible.
200
#
201
202
class UnableToCaptureScreenError < WebDriverError; end
203
204
#
205
# Occurs if the given session id is not in the list of active sessions, meaning the session
206
# either does not exist or that it's not active.
207
#
208
209
class InvalidSessionIdError < WebDriverError; end
210
211
#
212
# A modal dialog was open, blocking this operation.
213
#
214
215
class UnexpectedAlertOpenError < WebDriverError; end
216
217
#
218
# The requested command matched a known URL but did not match an method for that URL.
219
#
220
221
class UnknownMethodError < WebDriverError; end
222
223
#
224
# The Element Click command could not be completed because the element receiving the events
225
# is obscuring the element that was requested clicked.
226
#
227
228
class ElementClickInterceptedError < WebDriverError; end
229
230
#
231
# Indicates that a command that should have executed properly cannot be supported for some
232
# reason.
233
#
234
235
class UnsupportedOperationError < WebDriverError; end
236
237
#
238
# Indicates that driver was not specified and could not be located.
239
#
240
241
class NoSuchDriverError < WebDriverError; end
242
end # Error
243
end # WebDriver
244
end # Selenium
245
246