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.
This article will provide you with a list of common 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 the compile-time exception as it causes problems while running Automation pack in headless.
The list of common exceptions in Selenium
1. RemoteDriverServerException: This Selenium exception is thrown when the server does not respond due to the problem that the capabilities described are not proper.
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 Selenium exception happens 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 driverserver or browser may not support the profiles.
9. WebDriverException: This takes place when the WebDriver is performing the action right after you close the browser.
“Exception” is a quite common term when it comes to programming, regardless of which language you use to write codes. Therefore, we have listed all types of exceptions in Selenium along with their explanations. From here, you can create robust and optimal codes in Selenium as well as Katalon Studio by handling these exceptions wisely. We hope this article will be a quick reference for you to tackle exceptions in Selenium and Katalon Studio.