1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import
import traceback
import six
@six.python_2_unicode_compatible
class MarionetteException(Exception):
"""Raised when a generic non-recoverable exception has occured."""
status = "webdriver error"
def __init__(self, message=None, cause=None, stacktrace=None):
"""Construct new MarionetteException instance.
:param message: An optional exception message.
:param cause: An optional tuple of three values giving
information about the root exception cause. Expected
tuple values are (type, value, traceback).
:param stacktrace: Optional string containing a stacktrace
(typically from a failed JavaScript execution) that will
be displayed in the exception's string representation.
"""
self.cause = cause
self.stacktrace = stacktrace
self._message = six.text_type(message)
def __str__(self):
# pylint: disable=W1645
msg = self.message
tb = None
if self.cause:
if type(self.cause) is tuple:
msg += u", caused by {0!r}".format(self.cause[0])
tb = self.cause[2]
else:
msg += u", caused by {}".format(self.cause)
if self.stacktrace:
st = u"".join(["\t{}\n".format(x) for x in self.stacktrace.splitlines()])
msg += u"\nstacktrace:\n{}".format(st)
if tb:
msg += u": " + u"".join(traceback.format_tb(tb))
return six.text_type(msg)
@property
def message(self):
return self._message
class ElementNotSelectableException(MarionetteException):
status = "element not selectable"
class ElementClickInterceptedException(MarionetteException):
status = "element click intercepted"
class InsecureCertificateException(MarionetteException):
status = "insecure certificate"
class InvalidArgumentException(MarionetteException):
status = "invalid argument"
class InvalidSessionIdException(MarionetteException):
status = "invalid session id"
class TimeoutException(MarionetteException):
status = "timeout"
class JavascriptException(MarionetteException):
status = "javascript error"
class NoSuchElementException(MarionetteException):
status = "no such element"
class NoSuchWindowException(MarionetteException):
status = "no such window"
class StaleElementException(MarionetteException):
status = "stale element reference"
class ScriptTimeoutException(MarionetteException):
status = "script timeout"
class ElementNotVisibleException(MarionetteException):
"""Deprecated. Will be removed with the release of Firefox 54."""
status = "element not visible"
def __init__(
self,
message="Element is not currently visible and may not be manipulated",
stacktrace=None,
cause=None,
):
super(ElementNotVisibleException, self).__init__(
message, cause=cause, stacktrace=stacktrace
)
class ElementNotAccessibleException(MarionetteException):
status = "element not accessible"
class ElementNotInteractableException(MarionetteException):
status = "element not interactable"
class NoSuchFrameException(MarionetteException):
status = "no such frame"
class InvalidElementStateException(MarionetteException):
status = "invalid element state"
class NoAlertPresentException(MarionetteException):
status = "no such alert"
class InvalidCookieDomainException(MarionetteException):
status = "invalid cookie domain"
class UnableToSetCookieException(MarionetteException):
status = "unable to set cookie"
class InvalidElementCoordinates(MarionetteException):
status = "invalid element coordinates"
class InvalidSelectorException(MarionetteException):
status = "invalid selector"
class MoveTargetOutOfBoundsException(MarionetteException):
status = "move target out of bounds"
class SessionNotCreatedException(MarionetteException):
status = "session not created"
class UnexpectedAlertOpen(MarionetteException):
status = "unexpected alert open"
class UnknownCommandException(MarionetteException):
status = "unknown command"
class UnknownException(MarionetteException):
status = "unknown error"
class UnsupportedOperationException(MarionetteException):
status = "unsupported operation"
class UnresponsiveInstanceException(Exception):
pass
es_ = [
e
for e in locals().values()
if type(e) == type and issubclass(e, MarionetteException)
]
by_string = {e.status: e for e in es_}
def lookup(identifier):
"""Finds error exception class by associated Selenium JSON wire
protocol number code, or W3C WebDriver protocol string.
"""
return by_string.get(identifier, MarionetteException)
|