November 23

0  comments

  1. InvalidArgumentException
  2. UnhandledAlertException
  3. NoAlertPresentException
  4. InvalidSelectorException
  5. NoSuchElementException
  6. TimeoutException
  7. NoSuchSessionException
  8. ElementNotVisibleException
  9. StaleElementReferenceException
  10. Compound class names not permitted
  11. Element not clickable at point (yy, zz)
  12. NoSuchFrameException
  13. NoSuchWindowException

InvalidArgumentException
InvalidArgumentException is thrown when we do not include https:// or http:// in the url.

Notice below, we get InvalidArgumentException since https:// is missing in url

To resolve this exception, we have to simply include https:// as shown below

Now if you run, there is no exception and the website launches

UnhandledAlertException

We get UnhandledAlertException when we try to close the browser without accepting or dismissing the alert. 

So let us launch

There is ‘Confirmation Alert’ button at the page bottom

Click the button, the alert popup comes up 

If we try to close the browser without clicking ‘OK’, we will get UnhandledAlertException.

See below, line#15 clicks the button and the alert pops up. Without accepting this alert, we are closing the browser (line#16)

To resolve UnhandledAlertException, we have to simply accept the alert, see below, we don’t get the exception now

NoAlertPresentException

NoAlertPresentException is thrown when selenium tries to accept or dismiss an alert that is not yet displayed.

To resolve this, selenium should wait for the alert to display.

InvalidSelectorException

InvalidSelectorException is thrown when there is a syntax error in xpath.

See below, we have an extra closing square bracket ]

When we run the script, we get an exception

Simply correct the syntax to resolve the exception

Now there is no exception and the page opens

NoSuchElementException

This exception is thrown when the element is not found on the webpage. In the below case, the xpath is incorrect and hence Selenium is not able to locate the element 

TimeoutException

Selenium, by default, waits indefinitely for a website page to load. However, we can instruct selenium to load the page within ‘t’ seconds. 

TimeoutException is thrown if the page does not load within ‘t’ seconds.

In the example below, we have set the page load timeout limit of 3 seconds. Notice that we get an exception, since the website page did not load within 3 seconds  

To resolve this exception, you can increase the page load timeout. 

NoSuchSessionException

NoSuchSessionException occurs when we try to perform an operation on a closed browser session

ElementNotVisibleException

ElementNotVisibleException is thrown when an object is present in DOM (document object model) but it is hidden on the web page. This exception can also occur if the object is not properly loaded.  Thus, if selenium tries to perform an operation on hidden element, ElementNotVisibleException will be thrown.

StaleElementReferenceException

In line#17, we are creating a reference to the text area. 

In line#18, we are refreshing the page and in line#19 we are trying to use the reference we created in line#17 which is no longer there (the reference becomes stale since the page is refreshed). Thus we get  StaleElementReferenceException

Compound class names not permitted

Notice below in line#16, there is a space between 2 classnames. In this scenario, we will get ‘Compound class names not permitted’ error

To resolve this, we should replace spaces with . within classnames, example

Element not clickable at point (yy, zz)

This error occurs when the element is not at the expected exact location. Due to this, selenium does not click the element.

NoSuchFrameException

NoSuchFrameException is thrown when selenium is not able to find the desired frame

NoSuchWindowException

NoSuchWindowException is thrown when selenium is not able to find the desired window

So these were the various exceptions in selenium.

Thanks.


Tags


You may also like

Groups attribute in TestNG 

Groups attribute in TestNG 
Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}