Path: blob/trunk/rb/lib/selenium/webdriver/common/error.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Error22#23# Returns exception from its string representation.24# @param [String, nil] error25#2627def self.for_error(error)28return if error.nil?2930klass_name = error.split.map(&:capitalize).join.sub(/Error$/, '')31const_get(:"#{klass_name}Error", false)32rescue NameError33WebDriverError34end3536SUPPORT_MSG = 'For documentation on this error, please visit:'37ERROR_URL = 'https://www.selenium.dev/documentation/webdriver/troubleshooting/errors'3839URLS = {40NoSuchElementError: "#{ERROR_URL}#no-such-element-exception",41StaleElementReferenceError: "#{ERROR_URL}#stale-element-reference-exception",42InvalidSelectorError: "#{ERROR_URL}#invalid-selector-exception",43NoSuchDriverError: "#{ERROR_URL}/driver_location"44}.freeze4546class WebDriverError < StandardError47def initialize(msg = '')48# Remove this conditional when all the error pages have been documented49super(URLS[class_name] ? "#{msg}; #{SUPPORT_MSG} #{URLS[class_name]}" : msg)50end5152# steep:ignore:start53def class_name54self.class.name.split('::')&.last&.to_sym55end56# steep:ignore:end57end5859#60# An element could not be located on the page using the given search parameters.61#6263class NoSuchElementError < WebDriverError; end6465#66# A command to switch to a frame could not be satisfied because the frame could not be found.67#6869class NoSuchFrameError < WebDriverError; end7071#72# A command could not be executed because the remote end is not aware of it.73#7475class UnknownCommandError < WebDriverError; end7677#78# A command failed because the referenced element is no longer attached to the DOM.79#8081class StaleElementReferenceError < WebDriverError; end8283#84# A command failed because the referenced shadow root is no longer attached to the DOM.85#8687class DetachedShadowRootError < WebDriverError; end8889#90# The target element is in an invalid state, rendering it impossible to interact with, for91# example if you click a disabled element.92#9394class InvalidElementStateError < WebDriverError; end9596#97# An unknown error occurred in the remote end while processing the command.98#99100class UnknownError < WebDriverError; end101102#103# An error occurred while executing JavaScript supplied by the user.104#105106class JavascriptError < WebDriverError; end107108#109# An operation did not complete before its timeout expired.110#111112class TimeoutError < WebDriverError; end113114#115# A command to switch to a window could not be satisfied because116# the window could not be found.117#118119class NoSuchWindowError < WebDriverError; end120121#122# The element does not have a shadow root.123#124125class NoSuchShadowRootError < WebDriverError; end126127#128# An illegal attempt was made to set a cookie under a different domain than the current page.129#130131class InvalidCookieDomainError < WebDriverError; end132133#134# A command to set a cookie's value could not be satisfied.135#136137class UnableToSetCookieError < WebDriverError; end138139#140# An attempt was made to operate on a modal dialog when one was not open:141#142143class NoSuchAlertError < WebDriverError; end144145#146# A script did not complete before its timeout expired.147#148149class ScriptTimeoutError < WebDriverError; end150151#152# Argument was an invalid selector.153#154155class InvalidSelectorError < WebDriverError; end156157#158# A new session could not be created.159#160161class SessionNotCreatedError < WebDriverError; end162163#164# The target for mouse interaction is not in the browser's viewport and cannot be brought165# into that viewport.166#167168class MoveTargetOutOfBoundsError < WebDriverError; end169170#171# A command could not be completed because the element is not pointer or keyboard172# interactable.173#174175class ElementNotInteractableError < WebDriverError; end176177#178# A command could not be completed because TLS certificate is expired179# or invalid.180#181182class InsecureCertificateError < WebDriverError; end183184#185# The arguments passed to a command are either invalid or malformed.186#187188class InvalidArgumentError < WebDriverError; end189190#191# No cookie matching the given path name was found amongst the associated cookies of the192# current browsing context's active document.193#194195class NoSuchCookieError < WebDriverError; end196197#198# A screen capture was made impossible.199#200201class UnableToCaptureScreenError < WebDriverError; end202203#204# Occurs if the given session id is not in the list of active sessions, meaning the session205# either does not exist or that it's not active.206#207208class InvalidSessionIdError < WebDriverError; end209210#211# A modal dialog was open, blocking this operation.212#213214class UnexpectedAlertOpenError < WebDriverError; end215216#217# The requested command matched a known URL but did not match an method for that URL.218#219220class UnknownMethodError < WebDriverError; end221222#223# The Element Click command could not be completed because the element receiving the events224# is obscuring the element that was requested clicked.225#226227class ElementClickInterceptedError < WebDriverError; end228229#230# Indicates that a command that should have executed properly cannot be supported for some231# reason.232#233234class UnsupportedOperationError < WebDriverError; end235236#237# Indicates that driver was not specified and could not be located.238#239240class NoSuchDriverError < WebDriverError; end241end # Error242end # WebDriver243end # Selenium244245246