Selenium Webdriver - Exceptions

If an error occurs, any of the methods fail or an unexpected error happens, an exception is thrown. In Python, all the exceptions are obtained from the BaseException class.
Some of the common Selenium Exceptions are listed below −
ElementNotInteractableException − It is thrown if a webelement is attached to the DOM, but on trying to access the same webelement a different webelement gets accessed.
ElementNotInteractableException − It is thrown if a webelement is attached to the DOM, but on trying to access the same webelement a different webelement gets accessed.
ElementClickInterceptedException − It is thrown if a click operation on a webelement could not happen because another webelement covering that webelement receives the click.
ElementClickInterceptedException − It is thrown if a click operation on a webelement could not happen because another webelement covering that webelement receives the click.
ElementNotVisibleException − It is thrown if a webelement is attached to the DOM, but invisible on the page and inaccessible.
ElementNotVisibleException − It is thrown if a webelement is attached to the DOM, but invisible on the page and inaccessible.
ElementNotSelectableException − It is thrown if we make an attempt to select a webelement which is not selectable.
ElementNotSelectableException − It is thrown if we make an attempt to select a webelement which is not selectable.
ImeActivationFailedException − It is thrown if we fail to activate an IME engine.
ImeActivationFailedException − It is thrown if we fail to activate an IME engine.
ErrorInResponseException − It is thrown if there is an issue on the server side.
ErrorInResponseException − It is thrown if there is an issue on the server side.
InsecureCertificateException − It is thrown if a user gets a certificate warning while navigating an application. It is due to a TLS certificate which is no longer active and valid.
InsecureCertificateException − It is thrown if a user gets a certificate warning while navigating an application. It is due to a TLS certificate which is no longer active and valid.
ImeNotAvailableException − It is thrown if there is no support for the IME engine.
ImeNotAvailableException − It is thrown if there is no support for the IME engine.
InvalidCookieDomainException − It is thrown if we try to add a cookie under a varied domain than the present URL.
InvalidCookieDomainException − It is thrown if we try to add a cookie under a varied domain than the present URL.
InvalidArgumentException − It is thrown if the argument passed to a command is no longer valid.
InvalidArgumentException − It is thrown if the argument passed to a command is no longer valid.
InvalidElementStateException − It is thrown if we try to access a webelement which is not in a valid state.
InvalidElementStateException − It is thrown if we try to access a webelement which is not in a valid state.
InvalidCoordinatesException − It is thrown if the coordinates for interactions are not valid.
InvalidCoordinatesException − It is thrown if the coordinates for interactions are not valid.
InvalidSessionIdException − It is thrown if the session id is not available in the group of live sessions. Thus the given session is either non-existent or inactive.
InvalidSessionIdException − It is thrown if the session id is not available in the group of live sessions. Thus the given session is either non-existent or inactive.
InvalidSelectorException − It is thrown if the locator used to identify an element does not yield a webelement.
InvalidSelectorException − It is thrown if the locator used to identify an element does not yield a webelement.
MoveTargetOutOfBoundsException − It is thrown if the target given in the ActionChains method is out of the scope of the document.
MoveTargetOutOfBoundsException − It is thrown if the target given in the ActionChains method is out of the scope of the document.
InvalidSwitchToTargetException − It is thrown if the frame id/name or the window handle id to be switched to is incorrect.
InvalidSwitchToTargetException − It is thrown if the frame id/name or the window handle id to be switched to is incorrect.
NoSuchAttributeException − It is thrown if an element attribute is not detected.
NoSuchAttributeException − It is thrown if an element attribute is not detected.
NoAlertPresentException − It is thrown if we try to switch to an alert which is non-existent.
NoAlertPresentException − It is thrown if we try to switch to an alert which is non-existent.
NoSuchFrameException − It is thrown if we try to switch to a frame which is non-existent.
NoSuchFrameException − It is thrown if we try to switch to a frame which is non-existent.
StaleElementReferenceException − It is thrown if an element reference is currently stale.
StaleElementReferenceException − It is thrown if an element reference is currently stale.
NoSuchWindowException − It is thrown if we try to switch to a window which is non-existent.
NoSuchWindowException − It is thrown if we try to switch to a window which is non-existent.
UnexpectedAlertPresentException − It is thrown if an alert appears unexpectedly in an automation flow.
UnexpectedAlertPresentException − It is thrown if an alert appears unexpectedly in an automation flow.
UnableToSetCookieException − It is thrown if the webdriver is unsuccessful in setting a cookie.
UnableToSetCookieException − It is thrown if the webdriver is unsuccessful in setting a cookie.
UnexpectedTagNameException − It is thrown if a support class has not received an anticipated webelement.
UnexpectedTagNameException − It is thrown if a support class has not received an anticipated webelement.
NoSuchElementException − It is thrown if the selector used is unable to locate a webelement.
NoSuchElementException − It is thrown if the selector used is unable to locate a webelement.
Let us see an example of a code which throws an exception.
The code implementation for the Selenium Exceptions is as follows −
from selenium import webdriver
driver = webdriver.Chrome(executable_path='../drivers/chromedriver')
#implicit wait time
driver.implicitly_wait(5)
#url launch
driver.get("https://www.tutorialspoint.com/about/about_careers.htm")
#identify element with an incorrect link text value
l = driver.find_element_by_link_text('Teams')
l.click()
#driver quit
driver.quit()
The output shows the message - Process with exit code 1 meaning that the above Python code has encountered an error. Also, NoSuchElementException is thrown since the locator link text is not able to detect the link Teams on the page.

    46 Lectures 
     5.5 hours 

 Aditya Dua

    296 Lectures 
     146 hours 

 Arun Motoori

    411 Lectures 
     38.5 hours 

 In28Minutes Official

    22 Lectures 
     7 hours 

 Arun Motoori

    118 Lectures 
     17 hours 

 Arun Motoori

    278 Lectures 
     38.5 hours 

 Lets Kode It
 Print
 Add Notes
 Bookmark this page