Module: Selenium::WebDriver::Error

Defined in:
lib/selenium/webdriver/common/error.rb,
lib/selenium/webdriver/remote/server_error.rb

Overview

rubocop:disable Metrics/ModuleLength

Defined Under Namespace

Classes: ElementClickInterceptedError, ElementNotInteractableError, ElementNotSelectableError, ElementNotVisibleError, ExpectedError, IMEEngineActivationFailedError, IMENotAvailableError, IndexOutOfBoundsError, InsecureCertificateError, InvalidArgumentError, InvalidCookieDomainError, InvalidElementCoordinatesError, InvalidElementStateError, InvalidSelectorError, InvalidSessionIdError, InvalidXpathSelectorError, InvalidXpathSelectorReturnTyperError, JavascriptError, MoveTargetOutOfBoundsError, NoAlertPresentError, NoCollectionError, NoScriptResultError, NoStringError, NoStringLengthError, NoStringWrapperError, NoSuchAlertError, NoSuchCollectionError, NoSuchCookieError, NoSuchDocumentError, NoSuchDriverError, NoSuchElementError, NoSuchFrameError, NoSuchWindowError, NullPointerError, ScriptTimeOutError, ServerError, SessionNotCreatedError, StaleElementReferenceError, TimeOutError, UnableToCaptureScreenError, UnableToSetCookieError, UnexpectedAlertOpenError, UnhandledAlertError, UnknownCommandError, UnknownError, UnknownMethodError, UnsupportedOperationError, WebDriverError, XPathLookupError

Constant Summary collapse

ScriptTimeoutError =

Aliases for OSS dialect.

Class.new(ScriptTimeOutError)
TimeoutError =
Class.new(TimeOutError)
NoAlertOpenError =
Class.new(NoAlertPresentError)
ObsoleteElementError =

Aliases for backwards compatibility.

Class.new(StaleElementReferenceError)
UnhandledError =
Class.new(UnknownError)
UnexpectedJavascriptError =
Class.new(JavascriptError)
ElementNotDisplayedError =
Class.new(ElementNotVisibleError)
ERRORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  1 => IndexOutOfBoundsError,
  2 => NoCollectionError,
  3 => NoStringError,
  4 => NoStringLengthError,
  5 => NoStringWrapperError,
  6 => NoSuchDriverError,
  7 => NoSuchElementError,
  8 => NoSuchFrameError,
  9 => UnknownCommandError,
  10 => StaleElementReferenceError,
  11 => ElementNotVisibleError,
  12 => InvalidElementStateError,
  13 => UnknownError,
  14 => ExpectedError,
  15 => ElementNotSelectableError,
  16 => NoSuchDocumentError,
  17 => JavascriptError,
  18 => NoScriptResultError,
  19 => XPathLookupError,
  20 => NoSuchCollectionError,
  21 => TimeOutError,
  22 => NullPointerError,
  23 => NoSuchWindowError,
  24 => InvalidCookieDomainError,
  25 => UnableToSetCookieError,
  26 => UnhandledAlertError,
  27 => NoAlertPresentError,
  28 => ScriptTimeOutError,
  29 => InvalidElementCoordinatesError,
  30 => IMENotAvailableError,
  31 => IMEEngineActivationFailedError,
  32 => InvalidSelectorError,
  33 => SessionNotCreatedError,
  34 => MoveTargetOutOfBoundsError,
  # The following are W3C-specific errors,
  # they don't really need error codes, we just make them up!
  51 => InvalidXpathSelectorError,
  52 => InvalidXpathSelectorReturnTyperError,
  60 => ElementNotInteractableError,
  61 => InvalidArgumentError,
  62 => NoSuchCookieError,
  63 => UnableToCaptureScreenError
}.freeze
DEPRECATED_ERRORS =
{
  IndexOutOfBoundsError: nil,
  NoCollectionError: nil,
  NoStringError: nil,
  NoStringLengthError: nil,
  NoStringWrapperError: nil,
  NoSuchDriverError: nil,
  ElementNotVisibleError: ElementNotInteractableError,
  InvalidElementStateError: ElementNotInteractableError,
  ElementNotSelectableError: ElementNotInteractableError,
  ExpectedError: nil,
  NoSuchDocumentError: nil,
  NoScriptResultError: nil,
  XPathLookupError: InvalidSelectorError,
  NoSuchCollectionError: nil,
  UnhandledAlertError: UnexpectedAlertOpenError,
  NoAlertPresentError: NoSuchAlertError,
  NoAlertOpenError: NoSuchAlertError,
  ScriptTimeOutError: ScriptTimeoutError,
  InvalidElementCoordinatesError: nil,
  IMENotAvailableError: nil,
  IMEEngineActivationFailedError: nil,
  InvalidXpathSelectorError: InvalidSelectorError,
  InvalidXpathSelectorReturnTyperError: InvalidSelectorError,
  TimeOutError: TimeoutError,
  ObsoleteElementError: StaleElementReferenceError,
  UnhandledError: UnknownError,
  UnexpectedJavascriptError: JavascriptError,
  ElementNotDisplayedError: ElementNotInteractableError
}.freeze

Class Method Summary collapse

Class Method Details

.const_missing(const_name) ⇒ Object


369
370
371
372
373
374
375
376
377
378
379
# File 'lib/selenium/webdriver/common/error.rb', line 369

def self.const_missing(const_name)
  super unless DEPRECATED_ERRORS.key?(const_name)
  if DEPRECATED_ERRORS[const_name]
    WebDriver.logger.deprecate("Selenium::WebDriver::Error::#{const_name}",
                               "#{DEPRECATED_ERRORS[const_name]} (ensure the driver supports W3C WebDriver specification)")
    DEPRECATED_ERRORS[const_name]
  else
    WebDriver.logger.deprecate("Selenium::WebDriver::Error::#{const_name}")
    WebDriverError
  end
end

.for_code(code) ⇒ Object

Returns exception from code (Integer - OSS, String - W3C).

Parameters:

  • code (Integer, String, nil)

29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/selenium/webdriver/common/error.rb', line 29

def self.for_code(code)
  case code
  when nil, 0
    nil
  when Integer
    Object.const_get(ERRORS.fetch(code).to_s)
  when String
    klass_name = code.split(' ').map(&:capitalize).join.sub(/Error$/, '')
    const_get("#{klass_name}Error", false)
  end
rescue KeyError, NameError
  WebDriverError
end