Selenium Exception 

Common Exceptions in Selenium Web driver

Exception nameDescription
ElementNotVisibleExceptionThis type of Selenium exception occurs when an existing element in DOM has a feature set as hidden.
ElementNotSelectableExceptionThis Selenium exception occurs when an element is presented in the DOM, but you can be able to select. Therefore, it is not possible to interact.
NoSuchElementExceptionThis Exception occurs if an element could not be found.
NoSuchFrameExceptionThis Exception occurs if the frame target to be switched to does not exist.
NoAlertPresentExceptionThis Exception occurs when you switch to no presented alert.
NoSuchWindowExceptionThis Exception occurs if the window target to be switch does not exist.
StaleElementReferenceExceptionThis Selenium exception occurs happens when the web element is detached from the current DOM.
SessionNotFoundExceptionThe WebDriver is acting after you quit the browser.
TimeoutExceptionThrown when there is not enough time for a command to be completed. For Example, the element searched wasn’t found in the specified time.
WebDriverExceptionThis Exception takes place when the WebDriver is acting right after you close the browser.
ConnectionClosedExceptionThis type of Exception takes place when there is a disconnection in the driver.
ElementClickInterceptedExceptionThe command may not be completed as the element receiving the events is concealing the element which was requested clicked.
ElementNotInteractableExceptionThis Selenium exception is thrown when any element is presented in the DOM. However, it is impossible to interact with such an element.
ErrorInResponseExceptionThis happens while interacting with the Firefox extension or the remote driver server.
ErrorHandler.UnknownServerExceptionException is used as a placeholder in case if the server returns an error without a stack trace.
ImeActivationFailedExceptionThis expectation will occur when IME engine activation has failed.
ImeNotAvailableExceptionIt takes place when IME support is unavailable.
InsecureCertificateExceptionNavigation made the user agent to hit a certificate warning. This can cause by an invalid or expired TLS certificate.
InvalidArgumentExceptionIt occurs when an argument does not belong to the expected type.
InvalidCookieDomainExceptionThis happens when you try to add a cookie under a different domain instead of current URL.
InvalidCoordinatesExceptionThis type of Exception matches an interacting operation that is not valid.
InvalidElementStateExceptioIt occurs when command can’t be finished when the element is invalid.
InvalidSessionIdExceptionThis Exception took place when the given session ID is not included in the list of active sessions. It means the session does not exist or is inactive either.
InvalidSwitchToTargetExceptionThis occurs when the frame or window target to be switched does not exist.
JavascriptExceptionThis issue occurs while executing JavaScript given by the user.
JsonExceptionIt occurs when you afford to get the session when the session is not created.
NoSuchAttributeExceptionThis kind of Exception occurs when the attribute of an element could not be found.
MoveTargetOutOfBoundsExceptionIt takes place if the target provided to the ActionChains move() methodology is not valid. For Example, out of the document.
NoSuchContextExceptionContextAware does mobile device testing.
NoSuchCookieExceptionThis Exception occurs when no cookie matching with the given pathname found for all the associated cookies of the currently browsing document.
NotFoundExceptionThis Exception is a subclass of WebDriverException. This will occur when an element on the DOM does not exist.
RemoteDriverServerExceptionThis Selenium exception is thrown when the server is not responding because of the problem that the capabilities described are not proper.
ScreenshotExceptionIt is not possible to capture a screen.
SessionNotCreatedExceptionIt happens when a new session could not be successfully created.
UnableToSetCookieExceptionThis occurs if a driver is unable to set a cookie.
UnexpectedTagNameExceptionHappens if a support class did not get a web element as expected.
UnhandledAlertExceptionThis expectation occurs when there is an alert, but WebDriver is not able to perform Alert operation.
UnexpectedAlertPresentExceptionIt occurs when there is the appearance of an unexpected alert.
UnknownMethodExceptionThis Exception happens when the requested command matches with a known URL but and not matching with a methodology for a specific URL.
UnreachableBrowserExceptionThis Exception occurs only when the browser is not able to be opened or crashed because of some reason.
UnsupportedCommandExceptionThis occurs when remote WebDriver does n’t send valid commands as expected.

Handling Selenium Exceptions

Here, are some important standard using which you can handle Exceptions in Selenium WebDriver:

Try-catch: This method can catch Exceptions, which uses a combination of the try and catch keywords. Try command indicates the start of the block, and Catch is placed at the end of the try block, which helps to resolve the Exception.

from selenium.common.exceptions import TimeoutException
try:
    element = WebDriverWait(driver, 2).until(
            EC.presence_of_element_located((By.XPATH, linkAddress))
    )
except TimeoutException as ex:
    print(ex.message)

OR

import selenium
try:
    element = WebDriverWait(driver, 2).until(
            EC.presence_of_element_located((By.XPATH, linkAddress))
    )
except selenium.common.exceptions.TimeoutException as ex:
    print(ex.message)
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇