Skip to content

Commit

Permalink
Add missing python W3C ErrorCodes (#4938)
Browse files Browse the repository at this point in the history
Aligns with Java Error Codes that are available
Closes #4556
  • Loading branch information
lmtierney authored and AutomatedTester committed Nov 8, 2017
1 parent aaf5a08 commit e8fdbae
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 4 deletions.
67 changes: 67 additions & 0 deletions py/selenium/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,70 @@ class InvalidArgumentException(WebDriverException):
The arguments passed to a command are either invalid or malformed.
"""
pass


class JavascriptException(WebDriverException):
"""
An error occurred while executing JavaScript supplied by the user.
"""
pass


class NoSuchCookieException(WebDriverException):
"""
No cookie matching the given path name was found amongst the associated cookies of the
current browsing context's active document.
"""
pass


class ScreenshotException(WebDriverException):
"""
A screen capture was made impossible.
"""
pass


class ElementClickInterceptedException(WebDriverException):
"""
The Element Click command could not be completed because the element receiving the events
is obscuring the element that was requested clicked.
"""
pass


class InsecureCertificateException(WebDriverException):
"""
Navigation caused the user agent to hit a certificate warning, which is usually the result
of an expired or invalid TLS certificate.
"""
pass


class InvalidCoordinatesException(WebDriverException):
"""
The coordinates provided to an interactions operation are invalid.
"""
pass


class InvalidSessionIdException(WebDriverException):
"""
Occurs if the given session id is not in the list of active sessions, meaning the session
either does not exist or that it's not active.
"""
pass


class SessionNotCreatedException(WebDriverException):
"""
A new session could not be created.
"""
pass


class UnknownMethodException(WebDriverException):
"""
The requested command matched a known URL but did not match an method for that URL.
"""
pass
51 changes: 47 additions & 4 deletions py/selenium/webdriver/remote/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@
# specific language governing permissions and limitations
# under the License.

from selenium.common.exceptions import (ElementNotInteractableException,
from selenium.common.exceptions import (ElementClickInterceptedException,
ElementNotInteractableException,
ElementNotSelectableException,
ElementNotVisibleException,
ErrorInResponseException,
InsecureCertificateException,
InvalidCoordinatesException,
InvalidElementStateException,
InvalidSessionIdException,
InvalidSelectorException,
ImeNotAvailableException,
ImeActivationFailedException,
InvalidArgumentException,
InvalidCookieDomainException,
JavascriptException,
MoveTargetOutOfBoundsException,
NoSuchCookieException,
NoSuchElementException,
NoSuchFrameException,
NoSuchWindowException,
NoAlertPresentException,
ScreenshotException,
SessionNotCreatedException,
StaleElementReferenceException,
TimeoutException,
UnableToSetCookieException,
UnexpectedAlertPresentException,
UnknownMethodException,
WebDriverException)

try:
Expand All @@ -52,7 +64,6 @@ class ErrorCode(object):
ELEMENT_NOT_VISIBLE = [11, 'element not visible']
INVALID_ELEMENT_STATE = [12, 'invalid element state']
UNKNOWN_ERROR = [13, 'unknown error']
ELEMENT_NOT_INTERACTABLE = ["element not interactable"]
ELEMENT_IS_NOT_SELECTABLE = [15, 'element not selectable']
JAVASCRIPT_ERROR = [17, 'javascript error']
XPATH_LOOKUP_ERROR = [19, 'invalid selector']
Expand All @@ -67,9 +78,21 @@ class ErrorCode(object):
IME_NOT_AVAILABLE = [30, 'ime not available']
IME_ENGINE_ACTIVATION_FAILED = [31, 'ime engine activation failed']
INVALID_SELECTOR = [32, 'invalid selector']
SESSION_NOT_CREATED = [33, 'session not created']
MOVE_TARGET_OUT_OF_BOUNDS = [34, 'move target out of bounds']
INVALID_XPATH_SELECTOR = [51, 'invalid selector']
INVALID_XPATH_SELECTOR_RETURN_TYPER = [52, 'invalid selector']

ELEMENT_NOT_INTERACTABLE = [60, 'element not interactable']
INSECURE_CERTIFICATE = ['insecure certificate']
INVALID_ARGUMENT = [61, 'invalid argument']
INVALID_COORDINATES = ['invalid coordinates']
INVALID_SESSION_ID = ['invalid session id']
NO_SUCH_COOKIE = [62, 'no such cookie']
UNABLE_TO_CAPTURE_SCREEN = [63, 'unable to capture screen']
ELEMENT_CLICK_INTERCEPTED = [64, 'element click intercepted']
UNKNOWN_METHOD = ['unknown method exception']

METHOD_NOT_ALLOWED = [405, 'unsupported operation']


Expand Down Expand Up @@ -136,9 +159,9 @@ def check_response(self, response):
elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
exception_class = ElementNotInteractableException
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
exception_class = WebDriverException
exception_class = InvalidCookieDomainException
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
exception_class = WebDriverException
exception_class = UnableToSetCookieException
elif status in ErrorCode.TIMEOUT:
exception_class = TimeoutException
elif status in ErrorCode.SCRIPT_TIMEOUT:
Expand All @@ -155,6 +178,26 @@ def check_response(self, response):
exception_class = ImeActivationFailedException
elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
exception_class = MoveTargetOutOfBoundsException
elif status in ErrorCode.JAVASCRIPT_ERROR:
exception_class = JavascriptException
elif status in ErrorCode.SESSION_NOT_CREATED:
exception_class = SessionNotCreatedException
elif status in ErrorCode.INVALID_ARGUMENT:
exception_class = InvalidArgumentException
elif status in ErrorCode.NO_SUCH_COOKIE:
exception_class = NoSuchCookieException
elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
exception_class = ScreenshotException
elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
exception_class = ElementClickInterceptedException
elif status in ErrorCode.INSECURE_CERTIFICATE:
exception_class = InsecureCertificateException
elif status in ErrorCode.INVALID_COORDINATES:
exception_class = InvalidCoordinatesException
elif status in ErrorCode.INVALID_SESSION_ID:
exception_class = InvalidSessionIdException
elif status in ErrorCode.UNKNOWN_METHOD:
exception_class = UnknownMethodException
else:
exception_class = WebDriverException
if value == '' or value is None:
Expand Down
Loading

0 comments on commit e8fdbae

Please sign in to comment.