Selenium Automation - Exceptions

Selenium Automation - Exceptions

In this article we are going to discuss about the kind of exceptions we may face while executing automation scripts on a web application using Selenium Web driver. An exception is an infallible statement; it will always tell you why something has gone wrong in the code. It may not always be easy to understand an exception, but it does always tell the information about what went wrong in the code. One of the good things in Selenium is that while looking into the exception we will come to know that what went wrong as the exception names will give somewhat clear picture of the errors we will face.

Below are the very frequent exceptions we'll see while automating an application:

1. NoSuchElementException

2. NoSuchFrameException

3. NoSuchWindowException

4. ElementNotVisibleException

5. StaleElementReferenceException

6. InvalidElementStateException

7. UnreachableBrowserException

8. SessionNotFoundException


1. NoSuchElementException

This is one of the most frequently happening exception. You might have definitely find this exception while automating an application. The reason for this exception is that the element you are trying to find does not exist. Means, let's imagine you are trying to find an element on a web page using a locator, i.e , XPath, ID, name etc but the element the locator is looking for does not exist on the web page, then the locator will not be able to find the element using the specified locator and the automation script will throw a NoSuchElementException.

2. NoSuchFrameException

This is also a commonly faced exception. In modern applications iframes are used very often. An iframe is an inline frame that can embed another document in the current html and is used when you want to show some extra external information on your web page. When you try to find an iframe on the web page, if it is not available then it will throw a NoSuchFrameException.

3. NoSuchWindowException

This is also very similar to the previous exception. A window is a browser which is opened by the web driver or a child window(that is another browser opened by the parent browser). When you try to find a window and if it is not available then it will throw NoSuchWindowException.

4. ElementNotVisibleException

This exception tells you that the web element that you are trying to interact with is not visible to the user. That means the script is trying to find an element that is not visible on the application.

5. StaleElementReferenceException

This is an exception that you will see if you have AJAX or heavy JavaScript content on your web page, where the DOM is continually being changed. In simple words DOM is the HTML written for the page. If the element is no longer attached to the DOM then you will get StaleElementReferenceException.

6. InvalidElementStateException

You won't get this exception very often. Imagine when you try to interact with an element and an unexpected pop-up threw but you are not sure how to handle it. An InvalidElementStateException is thrown when the web element that you are trying to interact with is not in a state that would allow you to perform the action that you would like to perform.

7. UnreacheableBrowserException

This is a not a common exception. As we know that selenium sends commands to the browser to execute an action and gets the response back. Selenium will send a command to the browser and it will perform something on that the browser which will give the response back. But sometimes we will not get the response from the browser due to various reasons then we will get the UnreacheableBrowserException.

8. SessionNotFoundException

You will not get this exception very often. While you execute your automation tests, something went wrong and you lost the connection with the browser instance. Then we will get the SessionNotFoundException.

These are some of the very common exceptions you will face while automating any application. In this article we have seen what are the common types of exceptions and why the exceptions occur. I hope you enjoyed reading this information.



要查看或添加评论,请登录

Jobin P.Sunny的更多文章

社区洞察

其他会员也浏览了