|
| 1 | +# Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The SFC licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +""" |
| 19 | +Exceptions that may happen in all the webdriver code. |
| 20 | +""" |
| 21 | + |
| 22 | + |
| 23 | +class WebDriverException(Exception): |
| 24 | + """ |
| 25 | + Base webdriver exception. |
| 26 | + """ |
| 27 | + |
| 28 | + def __init__(self, msg=None, screen=None, stacktrace=None): |
| 29 | + self.msg = msg |
| 30 | + self.screen = screen |
| 31 | + self.stacktrace = stacktrace |
| 32 | + |
| 33 | + def __str__(self): |
| 34 | + exception_msg = "Message: %s\n" % self.msg |
| 35 | + if self.screen is not None: |
| 36 | + exception_msg += "Screenshot: available via screen\n" |
| 37 | + if self.stacktrace is not None: |
| 38 | + stacktrace = "\n".join(self.stacktrace) |
| 39 | + exception_msg += "Stacktrace:\n%s" % stacktrace |
| 40 | + return exception_msg |
| 41 | + |
| 42 | + |
| 43 | +class ErrorInResponseException(WebDriverException): |
| 44 | + """ |
| 45 | + Thrown when an error has occurred on the server side. |
| 46 | +
|
| 47 | + This may happen when communicating with the firefox extension |
| 48 | + or the remote driver server. |
| 49 | + """ |
| 50 | + def __init__(self, response, msg): |
| 51 | + WebDriverException.__init__(self, msg) |
| 52 | + self.response = response |
| 53 | + |
| 54 | + |
| 55 | +class InvalidSwitchToTargetException(WebDriverException): |
| 56 | + """ |
| 57 | + Thrown when frame or window target to be switched doesn't exist. |
| 58 | + """ |
| 59 | + pass |
| 60 | + |
| 61 | + |
| 62 | +class NoSuchFrameException(InvalidSwitchToTargetException): |
| 63 | + """ |
| 64 | + Thrown when frame target to be switched doesn't exist. |
| 65 | + """ |
| 66 | + pass |
| 67 | + |
| 68 | + |
| 69 | +class NoSuchWindowException(InvalidSwitchToTargetException): |
| 70 | + """ |
| 71 | + Thrown when window target to be switched doesn't exist. |
| 72 | +
|
| 73 | + To find the current set of active window handles, you can get a list |
| 74 | + of the active window handles in the following way:: |
| 75 | +
|
| 76 | + print driver.window_handles |
| 77 | +
|
| 78 | + """ |
| 79 | + pass |
| 80 | + |
| 81 | + |
| 82 | +class NoSuchElementException(WebDriverException): |
| 83 | + """ |
| 84 | + Thrown when element could not be found. |
| 85 | +
|
| 86 | + If you encounter this exception, you may want to check the following: |
| 87 | + * Check your selector used in your find_by... |
| 88 | + * Element may not yet be on the screen at the time of the find operation, |
| 89 | + (webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait() |
| 90 | + for how to write a wait wrapper to wait for an element to appear. |
| 91 | + """ |
| 92 | + pass |
| 93 | + |
| 94 | + |
| 95 | +class NoSuchAttributeException(WebDriverException): |
| 96 | + """ |
| 97 | + Thrown when the attribute of element could not be found. |
| 98 | +
|
| 99 | + You may want to check if the attribute exists in the particular browser you are |
| 100 | + testing against. Some browsers may have different property names for the same |
| 101 | + property. (IE8's .innerText vs. Firefox .textContent) |
| 102 | + """ |
| 103 | + pass |
| 104 | + |
| 105 | + |
| 106 | +class StaleElementReferenceException(WebDriverException): |
| 107 | + """ |
| 108 | + Thrown when a reference to an element is now "stale". |
| 109 | +
|
| 110 | + Stale means the element no longer appears on the DOM of the page. |
| 111 | +
|
| 112 | +
|
| 113 | + Possible causes of StaleElementReferenceException include, but not limited to: |
| 114 | + * You are no longer on the same page, or the page may have refreshed since the element |
| 115 | + was located. |
| 116 | + * The element may have been removed and re-added to the screen, since it was located. |
| 117 | + Such as an element being relocated. |
| 118 | + This can happen typically with a javascript framework when values are updated and the |
| 119 | + node is rebuilt. |
| 120 | + * Element may have been inside an iframe or another context which was refreshed. |
| 121 | + """ |
| 122 | + pass |
| 123 | + |
| 124 | + |
| 125 | +class InvalidElementStateException(WebDriverException): |
| 126 | + """ |
| 127 | + Thrown when a command could not be completed because the element is in an invalid state. |
| 128 | +
|
| 129 | + This can be caused by attempting to clear an element that isn't both editable and resettable. |
| 130 | + """ |
| 131 | + pass |
| 132 | + |
| 133 | + |
| 134 | +class UnexpectedAlertPresentException(WebDriverException): |
| 135 | + """ |
| 136 | + Thrown when an unexpected alert is appeared. |
| 137 | +
|
| 138 | + Usually raised when when an expected modal is blocking webdriver form executing any |
| 139 | + more commands. |
| 140 | + """ |
| 141 | + def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None): |
| 142 | + super(UnexpectedAlertPresentException, self).__init__(msg, screen, stacktrace) |
| 143 | + self.alert_text = alert_text |
| 144 | + |
| 145 | + def __str__(self): |
| 146 | + return "Alert Text: %s\n%s" % (self.alert_text, super(UnexpectedAlertPresentException, self).__str__()) |
| 147 | + |
| 148 | + |
| 149 | +class NoAlertPresentException(WebDriverException): |
| 150 | + """ |
| 151 | + Thrown when switching to no presented alert. |
| 152 | +
|
| 153 | + This can be caused by calling an operation on the Alert() class when an alert is |
| 154 | + not yet on the screen. |
| 155 | + """ |
| 156 | + pass |
| 157 | + |
| 158 | + |
| 159 | +class ElementNotVisibleException(InvalidElementStateException): |
| 160 | + """ |
| 161 | + Thrown when an element is present on the DOM, but |
| 162 | + it is not visible, and so is not able to be interacted with. |
| 163 | +
|
| 164 | + Most commonly encountered when trying to click or read text |
| 165 | + of an element that is hidden from view. |
| 166 | + """ |
| 167 | + pass |
| 168 | + |
| 169 | + |
| 170 | +class ElementNotInteractableException(InvalidElementStateException): |
| 171 | + """ |
| 172 | + Thrown when an element is present in the DOM but interactions |
| 173 | + with that element will hit another element do to paint order |
| 174 | + """ |
| 175 | + pass |
| 176 | + |
| 177 | + |
| 178 | +class ElementNotSelectableException(InvalidElementStateException): |
| 179 | + """ |
| 180 | + Thrown when trying to select an unselectable element. |
| 181 | +
|
| 182 | + For example, selecting a 'script' element. |
| 183 | + """ |
| 184 | + pass |
| 185 | + |
| 186 | + |
| 187 | +class InvalidCookieDomainException(WebDriverException): |
| 188 | + """ |
| 189 | + Thrown when attempting to add a cookie under a different domain |
| 190 | + than the current URL. |
| 191 | + """ |
| 192 | + pass |
| 193 | + |
| 194 | + |
| 195 | +class UnableToSetCookieException(WebDriverException): |
| 196 | + """ |
| 197 | + Thrown when a driver fails to set a cookie. |
| 198 | + """ |
| 199 | + pass |
| 200 | + |
| 201 | + |
| 202 | +class RemoteDriverServerException(WebDriverException): |
| 203 | + """ |
| 204 | + """ |
| 205 | + pass |
| 206 | + |
| 207 | + |
| 208 | +class TimeoutException(WebDriverException): |
| 209 | + """ |
| 210 | + Thrown when a command does not complete in enough time. |
| 211 | + """ |
| 212 | + pass |
| 213 | + |
| 214 | + |
| 215 | +class MoveTargetOutOfBoundsException(WebDriverException): |
| 216 | + """ |
| 217 | + Thrown when the target provided to the `ActionsChains` move() |
| 218 | + method is invalid, i.e. out of document. |
| 219 | + """ |
| 220 | + pass |
| 221 | + |
| 222 | + |
| 223 | +class UnexpectedTagNameException(WebDriverException): |
| 224 | + """ |
| 225 | + Thrown when a support class did not get an expected web element. |
| 226 | + """ |
| 227 | + pass |
| 228 | + |
| 229 | + |
| 230 | +class InvalidSelectorException(NoSuchElementException): |
| 231 | + """ |
| 232 | + Thrown when the selector which is used to find an element does not return |
| 233 | + a WebElement. Currently this only happens when the selector is an xpath |
| 234 | + expression and it is either syntactically invalid (i.e. it is not a |
| 235 | + xpath expression) or the expression does not select WebElements |
| 236 | + (e.g. "count(//input)"). |
| 237 | + """ |
| 238 | + pass |
| 239 | + |
| 240 | + |
| 241 | +class ImeNotAvailableException(WebDriverException): |
| 242 | + """ |
| 243 | + Thrown when IME support is not available. This exception is thrown for every IME-related |
| 244 | + method call if IME support is not available on the machine. |
| 245 | + """ |
| 246 | + pass |
| 247 | + |
| 248 | + |
| 249 | +class ImeActivationFailedException(WebDriverException): |
| 250 | + """ |
| 251 | + Thrown when activating an IME engine has failed. |
| 252 | + """ |
| 253 | + pass |
| 254 | + |
| 255 | + |
| 256 | +class InvalidArgumentException(WebDriverException): |
| 257 | + """ |
| 258 | + The arguments passed to a command are either invalid or malformed. |
| 259 | + """ |
| 260 | + pass |
| 261 | + |
| 262 | + |
| 263 | +class JavascriptException(WebDriverException): |
| 264 | + """ |
| 265 | + An error occurred while executing JavaScript supplied by the user. |
| 266 | + """ |
| 267 | + pass |
| 268 | + |
| 269 | + |
| 270 | +class NoSuchCookieException(WebDriverException): |
| 271 | + """ |
| 272 | + No cookie matching the given path name was found amongst the associated cookies of the |
| 273 | + current browsing context's active document. |
| 274 | + """ |
| 275 | + pass |
| 276 | + |
| 277 | + |
| 278 | +class ScreenshotException(WebDriverException): |
| 279 | + """ |
| 280 | + A screen capture was made impossible. |
| 281 | + """ |
| 282 | + pass |
| 283 | + |
| 284 | + |
| 285 | +class ElementClickInterceptedException(WebDriverException): |
| 286 | + """ |
| 287 | + The Element Click command could not be completed because the element receiving the events |
| 288 | + is obscuring the element that was requested clicked. |
| 289 | + """ |
| 290 | + pass |
| 291 | + |
| 292 | + |
| 293 | +class InsecureCertificateException(WebDriverException): |
| 294 | + """ |
| 295 | + Navigation caused the user agent to hit a certificate warning, which is usually the result |
| 296 | + of an expired or invalid TLS certificate. |
| 297 | + """ |
| 298 | + pass |
| 299 | + |
| 300 | + |
| 301 | +class InvalidCoordinatesException(WebDriverException): |
| 302 | + """ |
| 303 | + The coordinates provided to an interactions operation are invalid. |
| 304 | + """ |
| 305 | + pass |
| 306 | + |
| 307 | + |
| 308 | +class InvalidSessionIdException(WebDriverException): |
| 309 | + """ |
| 310 | + Occurs if the given session id is not in the list of active sessions, meaning the session |
| 311 | + either does not exist or that it's not active. |
| 312 | + """ |
| 313 | + pass |
| 314 | + |
| 315 | + |
| 316 | +class SessionNotCreatedException(WebDriverException): |
| 317 | + """ |
| 318 | + A new session could not be created. |
| 319 | + """ |
| 320 | + pass |
| 321 | + |
| 322 | + |
| 323 | +class UnknownMethodException(WebDriverException): |
| 324 | + """ |
| 325 | + The requested command matched a known URL but did not match an method for that URL. |
| 326 | + """ |
| 327 | + pass |
0 commit comments