Exceptions in Selenium: Complete List, Causes & How to Handle Them

selenium exceptions

Selenium exceptions signal an element WebDriver can't find, a dropped session, or a timed-out command. See all 43 Selenium exceptions, what triggers each one, and how to handle them with try, catch, throw, and finally.

Key takeaways
The 30-second version of this article
Selenium exceptions occur when WebDriver hits an unexpected condition, such as a missing element, dropped session, or timeout.
In Java, almost all Selenium exceptions extend WebDriverException, a RuntimeException, so they are unchecked.
NoSuchElementException, StaleElementReferenceException, and TimeoutException are among the most common in practice.
Use try/catch, multiple catch blocks, finally, and throw/throws to handle exceptions cleanly.
Stable locators and proper wait strategies prevent many exceptions before they happen.

Selenium exceptions occur when WebDriver encounters an unexpected condition during test execution: an element it can't find, a session that's dropped, or a command that times out. If you're debugging a failing test, identifying the exception type is the fastest path to a fix.

This article covers all 43 exceptions in Selenium: what each one means, the conditions that cause it, and how to handle it. It applies whether you’re working in raw Selenium or a framework built on top of it, like Katalon True Platform.

What Are Selenium Exceptions?

Definition

An exception is an unusual or unexpected event that occurs while a program runs. It is a runtime error that disrupts the normal program flow.

Classification of Selenium Exceptions

In Java, exceptions fall into two types: checked exceptions and unchecked exceptions.

1. Checked exceptions

Checked exceptions are verified at compile time, so your code must either catch them or declare them with throws before it will compile.

2. Unchecked exceptions

Unchecked exceptions are thrown at runtime and don’t have to be declared or caught. In Selenium’s Java bindings, almost all exceptions extend WebDriverException, which is a RuntimeException, so they are unchecked. That’s why they often surface only when your automation runs, including in headless or CI runs.

The Complete List of Exceptions in Selenium

1. ConnectionClosedException: This exception takes place when there is a disconnection in the driver.

2. ElementClickInterceptedException: Thrown when the command can’t be completed because another element receiving the event is covering the element you tried to click.

3. ElementNotInteractableException: This Selenium exception is thrown when an element is presented in the DOM but it is impossible to interact with such element.

4. ElementNotSelectableException: This Selenium exception is thrown when an element is presented in the DOM but is unavailable for selection. Hence, it is impossible to interact with.

5. ElementNotVisibleException: Thrown when an element exists in the DOM but is hidden, so WebDriver can’t see or interact with it.

6. ErrorHandler.UnknownServerException: Exception is used as a placeholder if the server returns an error without a stack trace.

7. ErrorInResponseException: This exception is thrown when a fault has occurred on the server-side. You can see it happens when interacting with the Firefox extension or the remote driver server.

8. ImeActivationFailedException: This exception occurs when IME engine activation has failed.

9. ImeNotAvailableException: This exception takes place when IME support is unavailable.

10. InsecureCertificateException: Navigation made the user agent to hit a certificate warning, which is caused by an invalid or expired TLS certificate.

11. InvalidArgumentException: This Selenium exception is thrown if an argument does not belong to the expected type.

12. InvalidCookieDomainException: This happens when you try to add a cookie under a different domain rather than the current URL.

13. InvalidCoordinatesException: This happens if the coordinates offered to an interacting operation are not valid.

14. InvalidElementStateException: This Selenium exception occurs if a command cannot be finished as the element is invalid.

15. InvalidSessionIdException: Thrown when the given session ID is not in the list of active sessions, meaning the session doesn’t exist or is no longer active.

16. InvalidSwitchToTargetException: Happens if the frame or window target to be switched does not exist.

17. JavascriptException: This problem happens when executing JavaScript supplied by the user.

18. JsonException: Thrown when Selenium fails to parse or serialize JSON, for example when reading session capabilities from a session that wasn’t created.

19. MoveTargetOutOfBoundsException: Thrown if the target provided to an Actions move method is invalid, for example outside the document. It can come up when you drag and drop in Selenium.

20. NoAlertPresentException: Thrown when you try to switch to an alert that isn’t present.

21. NoSuchAttributeException: Occurs when the attribute of the element could not be found.

22. NoSuchContextException: Happens in mobile device testing and is thrown by ContextAware.

23. 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.

24. NoSuchElementException: Happens if an element could not be found.

25. NoSuchFrameException: Thrown if the frame to switch to does not exist.

26. NoSuchWindowException: Occurs if window target to be switched does not exist.

27. NotFoundException: This exception is a subclass of WebDriverException. It happens when an element on the DOM does not exist.

28. RemoteDriverServerException: This Selenium exception is thrown when the server does not respond due to the problem that the capabilities described are not proper.

29. ScreenshotException: It is impossible to capture a screen.

30. ScriptTimeoutException: Thrown when executeAsyncScript takes more time than the given time limit to return the value.

31. SessionNotCreatedException: A new session could not be successfully created.

32. SessionNotFoundException: The WebDriver is performing the action right after you quit the browser.

33. StaleElementReferenceException: This Selenium exception happens if the web element is detached from the current DOM.

34. TimeoutException: Thrown when there is not enough time for a command to be completed.

35. UnableToCreateProfileException: You can open a browser with certain options using profiles, but sometimes a new version of the Selenium driver server or browser may not support the profiles.

36. UnableToSetCookieException: Occurs if a driver is unable to set a cookie.

37. UnexpectedAlertPresentException: This Selenium exception happens when there is the appearance of an unexpected alert.

38. UnexpectedTagNameException: Happens if a support class did not get a web element as expected.

39. UnhandledAlertException: It happens when there is an alert, but WebDriver is unable to perform Alert operation.

40. UnknownMethodException: Thrown when the requested command matches with a known URL but not a method for that URL.

41. UnreachableBrowserException: This Selenium exception happens if the browser is unable to be opened or has crashed because of some reasons.

42. UnsupportedCommandException: Occurs when remote WebDriver does not send valid commands as expected.

43. WebDriverException: The base class for most Selenium exceptions. It is thrown for general WebDriver failures, for example when WebDriver tries to perform an action after the browser has been closed.

Selenium Exception Handling

What Is Exception Handling?

In a software program, an atypical event (e.g., an unrecognized message) can interrupt the regular execution flow. If not handled properly, these events can terminate the program. Exception handling is the process of managing these events to prevent such problems.

Exception Handling in Selenium: Methods and Examples

To handle the Selenium exceptions above, you can use these standard Java exception-handling constructs.

  • Throw/throws: The throw keyword rethrows an exception so the caller or runtime can handle it, and the throws clause declares that a method may throw it.
// Method signature
public static void anyFunction() throws Exception {
    try {
        // Write your code here
    } catch (Exception e) {
        // Do whatever you need to do here
        // Then rethrow the exception
        throw e;
    }
}
  • Multiple catch blocks: You can use multiple catch blocks to handle different exception types. The syntax looks like this:
try {
    // Some code
} catch (ExceptionType1 e1) {
    // Code for handling exception 1
} catch (ExceptionType2 e2) {
    // Code for handling exception 2
}
  • Try/catch: A try block encloses code that can throw an exception, and a catch block contains the logic for handling exceptions thrown in the try block. The syntax looks like this:
try {
    // Some code
} catch (Exception e) {
    // Code for handling the exception
}
  • Finally: A finally block contains code that runs whether or not an exception is thrown, such as closing the browser or releasing resources:
try {
    // Protected code
} catch (ExceptionType1 e1) {
    // Catch block
} catch (ExceptionType2 e2) {
    // Catch block
} finally {
    // The finally block always executes
}

Selenium Exception Examples

Example 1: Handling a TimeoutException in a Katalon Studio (Groovy) test built on Selenium WebDriver.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.TimeoutException
import com.kms.katalon.core.util.KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

try {
    WebUI.click(findTestObject('Page_Register/btn_register'))
} catch (TimeoutException toe) {
    WebUI.waitForElementClickable(findTestObject('Page_Register/btn_register'), 20)
    WebUI.click(findTestObject('Page_Register/btn_register'))
} catch (Exception e) {
    KeywordUtil.markError('Register button is not found.')
    throw e
}

Example 2: Let’s say you want to verify whether an element is present on the page. If the element exists, your locator works and you can report that it’s present. If it doesn’t, the lookup throws an exception and the test fails. A small helper function that catches the exception and returns true or false solves this.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.common.WebUiCommonHelper

boolean verifyObjectPresent() {
    try {
        WebUiCommonHelper.findWebElement(findTestObject('Page_Report/lblReport'), 20)
        return true
    } catch (Exception e) {
        return false
    }
}

Related Selenium how-tos

Conclusion

We have listed all 43 types of exceptions in Selenium along with the conditions that trigger them. Understanding these exceptions is only half the battle. The other half is building tests resilient enough to avoid them in the first place.

That means writing stable locators (see our guide on XPath and CSS selectors), applying proper wait strategies, and structuring your test architecture so failures surface quickly and clearly.

Katalon True Platform is built to reduce the friction that leads to these exceptions. Its AI capabilities, including the Root Cause Analyzer and Bug Reporter, help teams identify why a test failed and trace it back to the right code change without manual log digging. The Test Runner and Test Case Generator work directly from your requirements, while Kai, the platform-wide AI assistant, helps you build and refine test objects so your locators stay current as the UI evolves.

Whether you’re handling exceptions in a raw Selenium setup or scaling test automation across web, mobile, and API, Katalon True Platform gives your team the infrastructure to move faster with fewer surprises.

Frequently asked questions

Huyen Nguyen
Huyen NguyenTechnical Writer, Katalon

Huyen Nguyen is an experienced technical writer in the software testing industry. With strong technical expertise and a deep understanding of Katalon products, she creates clear, practical guides that support testers at every skill level.

Connect on LinkedIn →
Get started

Test everything. Ship with confidence.

From generating test cases to spotting failures, Katalon's AI works across your entire pipeline, automatically.

Live webinar

The Next Evolution of Manual Testing: Introducing Katalon AI Test Runner

Learn how to grow your QA team's capacity in the age of AI, then watch Katalon AI Test Runner turn manual test cases into automated runs, live.

2:00 to 3:00 PM IST
Almas AhmedSenior Account Manager
Sumit WankhedeSolutions Engineer Manager
Register now