Exception Handling

In this lesson, we’ll learn about the set of exceptions provided by the Selenium.

We'll cover the following

Selenium has its own set of exceptions while writing automation scripts. A programmer has to handle or throw those exceptions.

WebDriver exception #

All runtime exception classes in Selenium WebDriver come under the superclass WebDriverException.

The most common exceptions under WebDriverException class are:

  • NoSuchElementException - the element is not found during runtime using FindBy method
  • StaleElementReferenceException - the referenced element is no longer present on the DOM page
  • NoSuchWindowException - switching to an invalid window
  • InvalidSelectorException - wrong or invalid selector used to find an element
  • ElementNotSelectableException - the element present but disabled in the DOM
  • TimeoutException - the element didn’t display in the specified time
  • NoSuchFrameException - switching to an invalid frame
  • NoAlertPresentException - switching to an invalid alert
  • ElementNotVisibleException - when an element is present in the DOM but cannot be interacted with, e.g., Hidden Elements

Get hands-on with 1400+ tech skills courses.