Back to Appium

Errors

packages/base-driver/docs/mjsonwp/errors.md

7.9.05.3 KB
Original Source

Mobile JSON Wire Protocol Errors

This package exports a number of classes and methods related to Selenium error handling. There are error classes for each Selenium error type (see here, as well as the context errors in the mobile spec).

These classes, which are constructed with a string message (defaulting to the "Details" below), are available through the errors object exported by the module. They are

CodeClass NameDetails
MJSONWPError<sup>1</sup>Base class for other errors
6NoSuchDriverErrorA session is either terminated or not started
7NoSuchElementErrorAn element could not be located on the page using the given search parameters
8NoSuchFrameErrorA request to switch to a frame could not be satisfied because the frame could not be found
9UnknownCommandErrorThe requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
10StaleElementReferenceErrorAn element command failed because the referenced element is no longer attached to the DOM
11ElementNotVisibleErrorAn element command could not be completed because the element is not visible on the page
12InvalidElementStateErrorAn element command could not be completed because the element is in an invalid state (e.g., attempting to click a disabled element)
13UnknownErrorAn unknown server-side error occurred while processing the command
405NotYetImplementedErrorThe operation requested is not yet implemented by the driver
405NotImplementedErrorThe operation requested will not be implemented by the driver
15ElementIsNotSelectableErrorAn attempt was made to select an element that cannot be selected
17JavaScriptErrorAn error occurred while executing user supplied JavaScript
19XPathLookupErrorAn error occurred while searching for an element by XPath
21TimeoutErrorAn operation did not complete before its timeout expired
23NoSuchWindowErrorA request to switch to a different window could not be satisfied because the window could not be found
24InvalidCookieDomainErrorAn illegal attempt was made to set a cookie under a different domain than the current page
25UnableToSetCookieErrorA request to set a cookie's value could not be satisfied
26UnexpectedAlertOpenErrorA modal dialog was open, blocking this operation
27NoAlertOpenErrorAn attempt was made to operate on a modal dialog when one was not open
28ScriptTimeoutErrorA script did not complete before its timeout expired
29InvalidElementCoordinatesErrorThe coordinates provided to an interactions operation are invalid
30IMENotAvailableErrorInput Method Editor was not available
31IMEEngineActivationFailedErrorAn Input Method Editor engine could not be started
32InvalidSelectorErrorArgument was an invalid selector (e.g., XPath/CSS)
33SessionNotCreatedErrorA new session could not be created
34MoveTargetOutOfBoundsErrorTarget provided for a move action is out of bounds
35NoSuchContextErrorContext provided (e.g., WEBVIEW_42) does not exist
36InvalidContextErrorThe operation could not be performed in the current context
BadParametersError<sup>2</sup>The parameters specified for the operation are incorrect

<sup>1</sup> MJSONWPError is the base class for all errors that are part of the Selenium specification (i.e., all errors except BadParametersError), and not itself part of that specification. <sup>2</sup> BadParametersError is not part of the Selenium specification, but deals with request management.

There are, in addition, two helper methods for dealing with errors

isErrorType (err, type)

  • checks if the err object is a Mobile JSON Wire Protocol error of a particular type
  • arguments
    • err - the error object to test
    • type - the error class to test against
  • usage
    js
    import { errors, isErrorType } from 'appium-base-driver';
    
    try {
      // do some stuff...
    } catch (err) {
      if (isErrorType(err, errors.InvalidCookieDomainError)) {
        // process...
      }
    }
    

errorFromCode (code, message)

  • retrieve the appropriate error for an error code, with the supplied message.
  • arguments
    • code - the integer error code for a Mobile JSON Wire Protocol error
    • message - the message to be encapsulated in the error
  • usage
    js
    import { errors, errorFromCode } from 'appium-base-driver';
    
    let error = errorFromCode(6, 'an error has occurred');
    
    console.log(error instanceof errors.NoSuchDriverError);
    // => true
    
    console.log(error.message === 'an error has occurred');
    // => true