API Testing:



The Common Selenium Exceptions Cheat Sheet – Exceptions in Selenium

During automation in Selenium, you will come across various exceptions and need to deal with them. Even if you work with other automation testing tools such as Katalon Studio, you may still face these types of exceptions (because Katalon Studio is built on top of Selenium). They are, however, more easily fixable than bugs or errors as they can throw logical termination. Let’s see exceptions in Selenium in detail.

Selenium Exception

This article will provide you with a complete list of various exceptions in Selenium as well as the cases in which they occur.

But first, let’s have a look at some important information regarding the term “exception” in Selenium.

What are Selenium Exceptions?


An exception is known as an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. An exception is also considered as a fault.

Classification of Selenium exceptions

Selenium exceptions are divided into two types including Checked Exceptions and Unchecked Exceptions.

1. Checked Exceptions

Checked Exceptions are handled during the process of writing codes. These exceptions are handled before compiling the code, therefore, such exceptions are examined at the compile time.

2. Unchecked Exceptions

These exceptions are thrown at runtime. Unchecked exceptions are more catastrophic than compile-time exception as it causes problems while running Automation pack in headless.

Common Selenium Exceptions Cheat Sheet

  • StaleElementReferenceException: Stale means old, decayed, no longer fresh. Stale Element means an old element or no longer available element. Assume there is an element that is found on a web page referenced as a WebElement in WebDriver. If the DOM changes then the WebElement goes stale. If we try to interact with an element which is staled then the StaleElementReferenceException is thrown. Read more here
  • InvalidElementStateException: This Selenium exception occurs if a command cannot be finished as the element is invalid.
  • InvalidSessionIdException: Takes place when the given session ID is not included in the list of active sessions, which means the session does not exist or is inactive either.
  • InvalidSwitchToTargetException: Happens if frame or window target to be switched does not exist.
  • JavascriptException: This problem happens when executing JavaScript supplied by the user.
  • JsonException: Happens when you afford to get the session capabilities where the session is not created.
  • MoveTargetOutOfBoundsException: Takes place if the target provided to the ActionChains move() methodology is not valid. For example: out of document.
  • NoAlertPresentException: Happens when you switch to no presented alert.
  • NoSuchAttributeException: Occurs when the attribute of element could not be found.
  • NoSuchContextException: Happens in mobile device testing and is thrown by ContextAware.
  • NoSuchCookieException: This exception is thrown if there is no cookie matching with the given path name found amongst the associated cookies of the current browsing context’s active document.
  • NoSuchElementException: Happens if an element could not be found.
  • NoSuchFrameException: Takes place if frame target to be switch does not exist.
  • NoSuchWindowException: Occurs if window target to be switch does not exist.
  • NotFoundException: This exception is subclass of WebDriverException. It happens when an element on the DOM does not exist.
  • RemoteDriverServerException: This Selenium exception is thrown when server do not respond due to the problem that the capabilities described are not proper.
  • ScreenshotException: It is impossible to capture a screen.
  • ScriptTimeoutException: Thrown when executeAsyncScript takes more time than the given time limit to return the value.

Refer TestNG Exceptions


“Exception” is a quite common term when it comes to programming, regardless of which language you use to write codes. Therefore, we hope this article will be a quick reference for you to tackle exceptions in Selenium and Katalon Studio. From here, you can create robust and optimal codes in Selenium as well as Katalon Studio by handling these exceptions wisely.

Sharing is caring.

Share on facebook
Share on twitter
Share on linkedin

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
API Testing eBook