Skip to content

Commit e8fdbae

Browse files
lmtierneyAutomatedTester
authored andcommitted
Add missing python W3C ErrorCodes (#4938)
Aligns with Java Error Codes that are available Closes #4556
1 parent aaf5a08 commit e8fdbae

3 files changed

Lines changed: 355 additions & 4 deletions

File tree

py/selenium/common/exceptions.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,70 @@ class InvalidArgumentException(WebDriverException):
255255
The arguments passed to a command are either invalid or malformed.
256256
"""
257257
pass
258+
259+
260+
class JavascriptException(WebDriverException):
261+
"""
262+
An error occurred while executing JavaScript supplied by the user.
263+
"""
264+
pass
265+
266+
267+
class NoSuchCookieException(WebDriverException):
268+
"""
269+
No cookie matching the given path name was found amongst the associated cookies of the
270+
current browsing context's active document.
271+
"""
272+
pass
273+
274+
275+
class ScreenshotException(WebDriverException):
276+
"""
277+
A screen capture was made impossible.
278+
"""
279+
pass
280+
281+
282+
class ElementClickInterceptedException(WebDriverException):
283+
"""
284+
The Element Click command could not be completed because the element receiving the events
285+
is obscuring the element that was requested clicked.
286+
"""
287+
pass
288+
289+
290+
class InsecureCertificateException(WebDriverException):
291+
"""
292+
Navigation caused the user agent to hit a certificate warning, which is usually the result
293+
of an expired or invalid TLS certificate.
294+
"""
295+
pass
296+
297+
298+
class InvalidCoordinatesException(WebDriverException):
299+
"""
300+
The coordinates provided to an interactions operation are invalid.
301+
"""
302+
pass
303+
304+
305+
class InvalidSessionIdException(WebDriverException):
306+
"""
307+
Occurs if the given session id is not in the list of active sessions, meaning the session
308+
either does not exist or that it's not active.
309+
"""
310+
pass
311+
312+
313+
class SessionNotCreatedException(WebDriverException):
314+
"""
315+
A new session could not be created.
316+
"""
317+
pass
318+
319+
320+
class UnknownMethodException(WebDriverException):
321+
"""
322+
The requested command matched a known URL but did not match an method for that URL.
323+
"""
324+
pass

py/selenium/webdriver/remote/errorhandler.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,34 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from selenium.common.exceptions import (ElementNotInteractableException,
18+
from selenium.common.exceptions import (ElementClickInterceptedException,
19+
ElementNotInteractableException,
1920
ElementNotSelectableException,
2021
ElementNotVisibleException,
2122
ErrorInResponseException,
23+
InsecureCertificateException,
24+
InvalidCoordinatesException,
2225
InvalidElementStateException,
26+
InvalidSessionIdException,
2327
InvalidSelectorException,
2428
ImeNotAvailableException,
2529
ImeActivationFailedException,
30+
InvalidArgumentException,
31+
InvalidCookieDomainException,
32+
JavascriptException,
2633
MoveTargetOutOfBoundsException,
34+
NoSuchCookieException,
2735
NoSuchElementException,
2836
NoSuchFrameException,
2937
NoSuchWindowException,
3038
NoAlertPresentException,
39+
ScreenshotException,
40+
SessionNotCreatedException,
3141
StaleElementReferenceException,
3242
TimeoutException,
43+
UnableToSetCookieException,
3344
UnexpectedAlertPresentException,
45+
UnknownMethodException,
3446
WebDriverException)
3547

3648
try:
@@ -52,7 +64,6 @@ class ErrorCode(object):
5264
ELEMENT_NOT_VISIBLE = [11, 'element not visible']
5365
INVALID_ELEMENT_STATE = [12, 'invalid element state']
5466
UNKNOWN_ERROR = [13, 'unknown error']
55-
ELEMENT_NOT_INTERACTABLE = ["element not interactable"]
5667
ELEMENT_IS_NOT_SELECTABLE = [15, 'element not selectable']
5768
JAVASCRIPT_ERROR = [17, 'javascript error']
5869
XPATH_LOOKUP_ERROR = [19, 'invalid selector']
@@ -67,9 +78,21 @@ class ErrorCode(object):
6778
IME_NOT_AVAILABLE = [30, 'ime not available']
6879
IME_ENGINE_ACTIVATION_FAILED = [31, 'ime engine activation failed']
6980
INVALID_SELECTOR = [32, 'invalid selector']
81+
SESSION_NOT_CREATED = [33, 'session not created']
7082
MOVE_TARGET_OUT_OF_BOUNDS = [34, 'move target out of bounds']
7183
INVALID_XPATH_SELECTOR = [51, 'invalid selector']
7284
INVALID_XPATH_SELECTOR_RETURN_TYPER = [52, 'invalid selector']
85+
86+
ELEMENT_NOT_INTERACTABLE = [60, 'element not interactable']
87+
INSECURE_CERTIFICATE = ['insecure certificate']
88+
INVALID_ARGUMENT = [61, 'invalid argument']
89+
INVALID_COORDINATES = ['invalid coordinates']
90+
INVALID_SESSION_ID = ['invalid session id']
91+
NO_SUCH_COOKIE = [62, 'no such cookie']
92+
UNABLE_TO_CAPTURE_SCREEN = [63, 'unable to capture screen']
93+
ELEMENT_CLICK_INTERCEPTED = [64, 'element click intercepted']
94+
UNKNOWN_METHOD = ['unknown method exception']
95+
7396
METHOD_NOT_ALLOWED = [405, 'unsupported operation']
7497

7598

@@ -136,9 +159,9 @@ def check_response(self, response):
136159
elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
137160
exception_class = ElementNotInteractableException
138161
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
139-
exception_class = WebDriverException
162+
exception_class = InvalidCookieDomainException
140163
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
141-
exception_class = WebDriverException
164+
exception_class = UnableToSetCookieException
142165
elif status in ErrorCode.TIMEOUT:
143166
exception_class = TimeoutException
144167
elif status in ErrorCode.SCRIPT_TIMEOUT:
@@ -155,6 +178,26 @@ def check_response(self, response):
155178
exception_class = ImeActivationFailedException
156179
elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
157180
exception_class = MoveTargetOutOfBoundsException
181+
elif status in ErrorCode.JAVASCRIPT_ERROR:
182+
exception_class = JavascriptException
183+
elif status in ErrorCode.SESSION_NOT_CREATED:
184+
exception_class = SessionNotCreatedException
185+
elif status in ErrorCode.INVALID_ARGUMENT:
186+
exception_class = InvalidArgumentException
187+
elif status in ErrorCode.NO_SUCH_COOKIE:
188+
exception_class = NoSuchCookieException
189+
elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
190+
exception_class = ScreenshotException
191+
elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
192+
exception_class = ElementClickInterceptedException
193+
elif status in ErrorCode.INSECURE_CERTIFICATE:
194+
exception_class = InsecureCertificateException
195+
elif status in ErrorCode.INVALID_COORDINATES:
196+
exception_class = InvalidCoordinatesException
197+
elif status in ErrorCode.INVALID_SESSION_ID:
198+
exception_class = InvalidSessionIdException
199+
elif status in ErrorCode.UNKNOWN_METHOD:
200+
exception_class = UnknownMethodException
158201
else:
159202
exception_class = WebDriverException
160203
if value == '' or value is None:

0 commit comments

Comments
 (0)