@@ -44,31 +44,31 @@ class ErrorCode(object):
44
44
"""
45
45
# Keep in sync with org.openqa.selenium.remote.ErrorCodes and errorcodes.h
46
46
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' ]
72
72
73
73
74
74
class ErrorHandler (object ):
@@ -78,54 +78,54 @@ class ErrorHandler(object):
78
78
def check_response (self , response ):
79
79
"""
80
80
Checks that a JSON response from the WebDriver does not have an error.
81
-
81
+
82
82
:Args:
83
83
- response - The JSON response from the WebDriver server as a dictionary
84
84
object.
85
-
85
+
86
86
:Raises: If the response contains an error message.
87
87
"""
88
88
status = response ['status' ]
89
89
if status == ErrorCode .SUCCESS :
90
90
return
91
91
exception_class = ErrorInResponseException
92
- if status == ErrorCode .NO_SUCH_ELEMENT :
92
+ if status in ErrorCode .NO_SUCH_ELEMENT :
93
93
exception_class = NoSuchElementException
94
- elif status == ErrorCode .NO_SUCH_FRAME :
94
+ elif status in ErrorCode .NO_SUCH_FRAME :
95
95
exception_class = NoSuchFrameException
96
- elif status == ErrorCode .NO_SUCH_WINDOW :
96
+ elif status in ErrorCode .NO_SUCH_WINDOW :
97
97
exception_class = NoSuchWindowException
98
- elif status == ErrorCode .STALE_ELEMENT_REFERENCE :
98
+ elif status in ErrorCode .STALE_ELEMENT_REFERENCE :
99
99
exception_class = StaleElementReferenceException
100
- elif status == ErrorCode .ELEMENT_NOT_VISIBLE :
100
+ elif status in ErrorCode .ELEMENT_NOT_VISIBLE :
101
101
exception_class = ElementNotVisibleException
102
- elif status == ErrorCode .INVALID_ELEMENT_STATE :
102
+ elif status in ErrorCode .INVALID_ELEMENT_STATE :
103
103
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 :
107
107
exception_class = InvalidSelectorException
108
- elif status == ErrorCode .ELEMENT_IS_NOT_SELECTABLE :
108
+ elif status in ErrorCode .ELEMENT_IS_NOT_SELECTABLE :
109
109
exception_class = ElementNotSelectableException
110
- elif status == ErrorCode .INVALID_COOKIE_DOMAIN :
110
+ elif status in ErrorCode .INVALID_COOKIE_DOMAIN :
111
111
exception_class = WebDriverException
112
- elif status == ErrorCode .UNABLE_TO_SET_COOKIE :
112
+ elif status in ErrorCode .UNABLE_TO_SET_COOKIE :
113
113
exception_class = WebDriverException
114
- elif status == ErrorCode .TIMEOUT :
114
+ elif status in ErrorCode .TIMEOUT :
115
115
exception_class = TimeoutException
116
- elif status == ErrorCode .SCRIPT_TIMEOUT :
116
+ elif status in ErrorCode .SCRIPT_TIMEOUT :
117
117
exception_class = TimeoutException
118
- elif status == ErrorCode .UNKNOWN_ERROR :
118
+ elif status in ErrorCode .UNKNOWN_ERROR :
119
119
exception_class = WebDriverException
120
- elif status == ErrorCode .UNEXPECTED_ALERT_OPEN :
120
+ elif status in ErrorCode .UNEXPECTED_ALERT_OPEN :
121
121
exception_class = UnexpectedAlertPresentException
122
- elif status == ErrorCode .NO_ALERT_OPEN :
122
+ elif status in ErrorCode .NO_ALERT_OPEN :
123
123
exception_class = NoAlertPresentException
124
- elif status == ErrorCode .IME_NOT_AVAILABLE :
124
+ elif status in ErrorCode .IME_NOT_AVAILABLE :
125
125
exception_class = ImeNotAvailableException
126
- elif status == ErrorCode .IME_ENGINE_ACTIVATION_FAILED :
126
+ elif status in ErrorCode .IME_ENGINE_ACTIVATION_FAILED :
127
127
exception_class = ImeActivationFailedException
128
- elif status == ErrorCode .MOVE_TARGET_OUT_OF_BOUNDS :
128
+ elif status in ErrorCode .MOVE_TARGET_OUT_OF_BOUNDS :
129
129
exception_class = MoveTargetOutOfBoundsException
130
130
else :
131
131
exception_class = WebDriverException
0 commit comments