Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Selenium Exceptions: The Complete List and Explanations

DZone's Guide to

Selenium Exceptions: The Complete List and Explanations

Understand all the different exceptions in Selenium automated testing and what they mean.

· Performance Zone ·
Free Resource

Sensu is an open source monitoring event pipeline. Try it today.

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.

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

  1. RemoteDriverServerException: This exception is thrown when the server does not respond because the capabilities described are not correct.

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

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

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

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

  6. StaleElementReferenceException: This exceptionhappens if the web element is detached from the current DOM.

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

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

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

  10. InvalidElementStateException: This exceptionoccurs if a command cannot be finished as the element is invalid.

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

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

  13. JavaScriptException: This problem happens when executing JavaScript supplied by the user.

  14. 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)

Conclusion

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

Sensu: workflow automation for monitoring. Learn more—download the whitepaper.

Topics:
selenium ,exceptions ,tutorial ,performance ,testing ,automated testing ,test automation ,performance testing

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}