+91 9790664230
kumar.arun211@gmail.com

Top 5 commonly encountered exceptions in Python Selenium WebDriver

Blog to learn python and selenium

Top 5 commonly encountered exceptions in Python Selenium WebDriver

1. NoSuchElementException

selenium.common.exceptions.NoSuchElementException
Base: selenium.common.exceptions.WebDriverException

This exception can be imported as ‘from selenium.common.exceptions import NoSuchElementException’

This exception is raised or thrown when element could not be found.

There could many possible reasons for this exception to occur
1. Element locator is not correct
2. Page is not yet loaded
3. Element is not yet displayed on the screen at the time of the find operation

2. StaleElementReferenceException

selenium.common.exceptions.StaleElementReferenceException
Base: selenium.common.exceptions.WebDriverException

This exception can be imported as ‘from selenium.common.exceptions import StaleElementReferenceException’

This exception is raised or thrown when a reference to an element is now “stale” – means that the element was available at the time of find operation but no longer appears on the DOM of the page while doing some operation.

There could many possible reasons for this exception to occur
1. The page is no longer the same or the page has been refreshed, since the element was located
2. The element may have been removed and re-added to the screen like relocation, since it was located
3. Element may have been inside a context which was refreshed

3. ElementNotVisibleException

selenium.common.exceptions.ElementNotVisibleException
Base: selenium.common.exceptions.InvalidElementStateException

This exception can be imported as ‘from selenium.common.exceptions import ElementNotVisibleException’

This exception is raised or thrown when an element is present on the DOM, but it is not visible.

This exception occurs most commonly when trying to click or read text of an element that is hidden from view.

4. ElementNotInteractableException

selenium.common.exceptions.ElementNotInteractableException
Base: selenium.common.exceptions.InvalidElementStateException

This exception can be imported as ‘from selenium.common.exceptions import ElementNotInteractableException’

This exception is raised or thrown when an element is present in the DOM but interactions with that element will hit another element

5. TimeoutException

selenium.common.exceptions.TimeoutException
Base: selenium.common.exceptions.WebDriverException

This exception can be imported as ‘from selenium.common.exceptions import TimeoutException’

This exception is raised or thrown when a command does not complete with in time. Like with in implicit or explicit wait time specified.

For more exception details – Visit Here

Please provide your opinion on comments.

 

Leave a Reply

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

© 2018 Copyrights. All Rights Reserved. Arunkumar Velusamy