Pallavi Sharma delivered a session on Selenium Exceptions at #ATATalk - Episode 1
Pallavi Sharma is acting as a coach, writer, speaker and owner at 5 Elements Learning where she collaborate and work with many learning enthusiasts and mentors around the globe and use her polyglot skills. An avid learner, she likes to keep herself updated to latest trends and technologies by attending conferences and workshops, and life has been kind enough to provide her with such experiences.
To know more about ATA Events please check : https://ataevents.org/
4. What is an Error
• Errors – An
unexpected
condition which
could be caused
by a programmer
of the system due
to lack of
resources.
• A programming
error can be
categorized into 3
sections
Error
Programmer
Syntax
RunTime
Logical
System Irrecoverable
5. What is an Exception
• An issue in the program
that causes disruption
in the normal execution
of the program
• Recoverable
• They can be handled
using various
programming keywords
• Generally classified as
checked exception and
unchecked exceptions
Exception
Checked
UnChecked
6. Exception in Selenium
• A class called as WebDriverException is defined.
• This class contains all the exceptions implemented which can
occur while working with Selenium.
• This page contains the details of the selenium exceptions –
https://www.selenium.dev/selenium/docs/api/java/org/openqa/s
elenium/class-use/WebDriverException.html
• The above information and examples will be shared using Java as
a programming language
8. org.openqa.selenium
• ElementClickInterceptedException
• Indicates that a click could not be properly executed
because the target element was obscured in some way.
• ElementNotInteractableException
• Thrown to indicate that although an element is present on
the DOM, it is not in a state that can be interacted with.
• ElementNotSelectableException
• Thrown to indicate that although an element is present on
the DOM, it is not selectable, and so is not able to be
interacted with.
• ElementNotVisibleException
• Thrown to indicate that although an element is present on
the DOM, it is not visible, and so is not able to be interacted
with.
9. Cont..
• ImeActivationFailedException
• Indicates that activating an IME engine has failed.
• ImeNotAvailableException
• Indicates that IME support is not available.
• InvalidArgumentException
• InvalidCookieDomainException
• Thrown when attempting to add a cookie under a different
domain than the current URL.
• InvalidElementStateException
• Indicates that a WebElement is in a state that means actions
cannot be performed with it.
• InvalidSelectorException
• JavascriptException
• NoAlertPresentException
• Indicates that a user has tried to access an alert when one is not
present.
10. Cont..
• NoSuchContextException
• Thrown by ContextAware.context(String)
WebDriver.switchTo().context(String name)}.
• NoSuchCookieException
• NoSuchElementException
• Thrown by WebDriver.findElement(By by) and
WebElement.findElement(By by).
• NoSuchFrameException
• Thrown by WebDriver.switchTo().frame(int frameIndex) and
WebDriver.switchTo().frame(String frameName).
• NoSuchSessionException T
• thrown by any command being called after WebDriver.quit().
• NoSuchWindowException
• Thrown by WebDriver.switchTo().window(String windowName).
• NotFoundException -
https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium
/NotFoundException.html
11. Cont..
• ScriptTimeoutException
• Thrown when an async execute script command does not
complete in enough time.
• SessionNotCreatedException
• Indicates that a session could not be created.
• StaleElementReferenceException
• Indicates that a reference to an element is now "stale" --- the
element no longer appears on the DOM of the page.
• TimeoutException
• Thrown when a command does not complete in enough time.
• UnableToSetCookieException
• Thrown when a driver fails to set a cookie.
• UnhandledAlertException
• UnsupportedCommandException
• Used to indicate that a command used by the remote webdriver
is unsupported.
12. Not Found Exceptions Examples
• https://www.selenium.dev/selenium/docs/api/java/or
g/openqa/selenium/NotFoundException.html
NoAlertPresentException NoSuchElementException
NoSuchFrameException NoSuchWindowException
14. Exception Handling- Technology Independent
• The concept of try catch finally block is found in all technologies.
• Within the try, we write code, which could be prone to exception
• Within catch/or except/or there could exists another word for it we
write code which works with the exception object once caught
• The finally block will have code which always executes whether
exception comes or not.
15. Selenium Exception or Technology Exception
• We need to understand selenium doesn’t work by itself.
• We will be using a programming language which comes with its own set of
errors and exception issues
• But the logic to implement the code to drive the browser to perform
actions on the website will not change and remain technology agnostic
• Similarly all the various interfaces whether it is data, third party tool
integration will have their own errors and exceptions as and when used in
code language of choice
16. Debugging Exceptions
• There is no code ever written which hasn’t generated an error or an exception.
• Exceptions are good, errors are good when you are learning.
• Take a good look at the error message generated, understand it, many times it
points to the code line, even if it doesn’t, copy the main message and search on
google for help
• The more readable the code is, the better it would be for debugging.
• Most commonly used IDE’s come up with debuggers which help in identifying the
source of error and exception faster than naked eye.