Selenium Exceptions: The Complete List and Explanations
Understand all the different exceptions in Selenium automated testing and what they mean.
Join the DZone community and get the full member experience.Join For Free
When running automated testing 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 a logical termination.
This article will provide you with a complete list of various exceptions in Selenium as well as the cases in which they occur. 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, Checked Exceptions and Unchecked Exceptions.
- Checked Exceptions
Checked Exceptions are handled during the process of writing code. These exceptions are handled before compiling the code, therefore, such exceptions are examined at compile time.
2. Unchecked Exceptions
These exceptions are thrown at runtime. Unchecked exceptions are more catastrophic than compile-time exceptions as they cause problems while running automation pack in headless mode.
Complete List of Exceptions in Selenium
RemoteDriverServerException: This exception is thrown when the server does not respond because the capabilities described are not correct.
ScreenshotException: It is impossible to capture a screen.
ScriptTimeoutException: Thrown when
executeAsyncScripttakes more time than the given time limit to return the value.
SessionNotCreatedException: A new session could not be successfully created.
SessionNotFoundException: The WebDriver is performing the action right after you quit the browser.
StaleElementReferenceException: This exceptionhappens if the web element is detached from the current DOM.
TimeoutException: Thrown when there is not enough time for a command to be completed.
UnableToCreateProfileException: You can open a browser with certain options using profiles, but sometimes a new version of Selenium driver, the server, or the browser may not support the profiles.
InvalidCoordinatesException: This happens if the coordinates offered to an interacting operation are not valid.
InvalidElementStateException: This exceptionoccurs 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.
InvalidSwitchToTargetException: Happens if the frame or window target to be switched does not exist.
JSONException: Happens when you try to get the session capabilities where a session is not created.
Besides, you can refer to the full list of Exceptions in Selenium (Updated 2018)
“Exception” is a quite common term when it comes to programming, regardless of which language you use to write code. 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.
Opinions expressed by DZone contributors are their own.