Skip to content

Commit 6af0f09

Browse files
author
AutomatedTester
committed
Allow python bindings to handle status codes as numbers and strings as steps to aligning with W3C Spec
1 parent 5f2e41b commit 6af0f09

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

py/selenium/webdriver/remote/errorhandler.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,31 @@ class ErrorCode(object):
4444
"""
4545
# Keep in sync with org.openqa.selenium.remote.ErrorCodes and errorcodes.h
4646
SUCCESS = 0
47-
NO_SUCH_ELEMENT = 7
48-
NO_SUCH_FRAME = 8
49-
UNKNOWN_COMMAND = 9
50-
STALE_ELEMENT_REFERENCE = 10
51-
ELEMENT_NOT_VISIBLE = 11
52-
INVALID_ELEMENT_STATE = 12
53-
UNKNOWN_ERROR = 13
54-
ELEMENT_IS_NOT_SELECTABLE = 15
55-
JAVASCRIPT_ERROR = 17
56-
XPATH_LOOKUP_ERROR = 19
57-
TIMEOUT = 21
58-
NO_SUCH_WINDOW = 23
59-
INVALID_COOKIE_DOMAIN = 24
60-
UNABLE_TO_SET_COOKIE = 25
61-
UNEXPECTED_ALERT_OPEN = 26
62-
NO_ALERT_OPEN = 27
63-
SCRIPT_TIMEOUT = 28
64-
INVALID_ELEMENT_COORDINATES = 29
65-
IME_NOT_AVAILABLE = 30;
66-
IME_ENGINE_ACTIVATION_FAILED = 31
67-
INVALID_SELECTOR = 32
68-
MOVE_TARGET_OUT_OF_BOUNDS = 34
69-
INVALID_XPATH_SELECTOR = 51
70-
INVALID_XPATH_SELECTOR_RETURN_TYPER = 52
71-
METHOD_NOT_ALLOWED = 405
47+
NO_SUCH_ELEMENT = [7, 'no such element']
48+
NO_SUCH_FRAME = [8, 'no such frame']
49+
UNKNOWN_COMMAND = [9, 'unknown command']
50+
STALE_ELEMENT_REFERENCE = [10, 'stale element reference']
51+
ELEMENT_NOT_VISIBLE = [11, 'element not visible']
52+
INVALID_ELEMENT_STATE = [12, 'invalid element state']
53+
UNKNOWN_ERROR = [13, 'unknown error']
54+
ELEMENT_IS_NOT_SELECTABLE = [15, 'element not selectable']
55+
JAVASCRIPT_ERROR = [17, 'javascript error']
56+
XPATH_LOOKUP_ERROR = [19, 'invalid selector']
57+
TIMEOUT = [21, 'timeout']
58+
NO_SUCH_WINDOW = [23, 'no such window']
59+
INVALID_COOKIE_DOMAIN = [24, 'invalid cookie domain']
60+
UNABLE_TO_SET_COOKIE = [25, 'unable to set cookie']
61+
UNEXPECTED_ALERT_OPEN = [26, 'unexpected alert open']
62+
NO_ALERT_OPEN = [27, 'no such alert']
63+
SCRIPT_TIMEOUT = [28, 'script timeout']
64+
INVALID_ELEMENT_COORDINATES = [29, 'invalid element coordinates']
65+
IME_NOT_AVAILABLE = [30, 'ime not available']
66+
IME_ENGINE_ACTIVATION_FAILED = [31, 'ime engine activation failed']
67+
INVALID_SELECTOR = [32, 'invalid selector']
68+
MOVE_TARGET_OUT_OF_BOUNDS = [34, 'move target out of bounds']
69+
INVALID_XPATH_SELECTOR = [51, 'invalid selector']
70+
INVALID_XPATH_SELECTOR_RETURN_TYPER = [52, 'invalid selector']
71+
METHOD_NOT_ALLOWED = [405, 'unsupported operation']
7272

7373

7474
class ErrorHandler(object):
@@ -78,54 +78,54 @@ class ErrorHandler(object):
7878
def check_response(self, response):
7979
"""
8080
Checks that a JSON response from the WebDriver does not have an error.
81-
81+
8282
:Args:
8383
- response - The JSON response from the WebDriver server as a dictionary
8484
object.
85-
85+
8686
:Raises: If the response contains an error message.
8787
"""
8888
status = response['status']
8989
if status == ErrorCode.SUCCESS:
9090
return
9191
exception_class = ErrorInResponseException
92-
if status == ErrorCode.NO_SUCH_ELEMENT:
92+
if status in ErrorCode.NO_SUCH_ELEMENT:
9393
exception_class = NoSuchElementException
94-
elif status == ErrorCode.NO_SUCH_FRAME:
94+
elif status in ErrorCode.NO_SUCH_FRAME:
9595
exception_class = NoSuchFrameException
96-
elif status == ErrorCode.NO_SUCH_WINDOW:
96+
elif status in ErrorCode.NO_SUCH_WINDOW:
9797
exception_class = NoSuchWindowException
98-
elif status == ErrorCode.STALE_ELEMENT_REFERENCE:
98+
elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
9999
exception_class = StaleElementReferenceException
100-
elif status == ErrorCode.ELEMENT_NOT_VISIBLE:
100+
elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
101101
exception_class = ElementNotVisibleException
102-
elif status == ErrorCode.INVALID_ELEMENT_STATE:
102+
elif status in ErrorCode.INVALID_ELEMENT_STATE:
103103
exception_class = InvalidElementStateException
104-
elif status == ErrorCode.INVALID_SELECTOR \
105-
or status == ErrorCode.INVALID_XPATH_SELECTOR \
106-
or status == ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
104+
elif status in ErrorCode.INVALID_SELECTOR \
105+
or status in ErrorCode.INVALID_XPATH_SELECTOR \
106+
or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
107107
exception_class = InvalidSelectorException
108-
elif status == ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
108+
elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
109109
exception_class = ElementNotSelectableException
110-
elif status == ErrorCode.INVALID_COOKIE_DOMAIN:
110+
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
111111
exception_class = WebDriverException
112-
elif status == ErrorCode.UNABLE_TO_SET_COOKIE:
112+
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
113113
exception_class = WebDriverException
114-
elif status == ErrorCode.TIMEOUT:
114+
elif status in ErrorCode.TIMEOUT:
115115
exception_class = TimeoutException
116-
elif status == ErrorCode.SCRIPT_TIMEOUT:
116+
elif status in ErrorCode.SCRIPT_TIMEOUT:
117117
exception_class = TimeoutException
118-
elif status == ErrorCode.UNKNOWN_ERROR:
118+
elif status in ErrorCode.UNKNOWN_ERROR:
119119
exception_class = WebDriverException
120-
elif status == ErrorCode.UNEXPECTED_ALERT_OPEN:
120+
elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
121121
exception_class = UnexpectedAlertPresentException
122-
elif status == ErrorCode.NO_ALERT_OPEN:
122+
elif status in ErrorCode.NO_ALERT_OPEN:
123123
exception_class = NoAlertPresentException
124-
elif status == ErrorCode.IME_NOT_AVAILABLE:
124+
elif status in ErrorCode.IME_NOT_AVAILABLE:
125125
exception_class = ImeNotAvailableException
126-
elif status == ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
126+
elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
127127
exception_class = ImeActivationFailedException
128-
elif status == ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
128+
elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
129129
exception_class = MoveTargetOutOfBoundsException
130130
else:
131131
exception_class = WebDriverException

0 commit comments

Comments
 (0)