0% found this document useful (0 votes)
19 views

Selenium Exceptions

Uploaded by

saiteja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Selenium Exceptions

Uploaded by

saiteja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

Here are the most important exceptions that QA testers commonly face
while working with Selenium WebDriver.

 NoSuchElementException: Thrown when an element with the given


locator is not found in the DOM.
 Example: If an element with a specific ID is not present on the page
when trying to interact with it.

 TimeoutException: Thrown when a command takes longer than the


specified wait time to complete.
 Example: If an element is not found within the time specified in an
explicit wait.

 ElementNotVisibleException: Thrown when an element is present


in the DOM but is not visible (not displayed).
 Example: Attempting to click on an element that is hidden from view.

 StaleElementReferenceException: Thrown when an element is no


longer attached to the DOM.
 Example: This occurs when the DOM structure changes and the
previously found element is no longer valid.

 NoSuchWindowException: Thrown when trying to switch to a


window that is not available.
 Example: When attempting to switch to a window that has been
closed.
SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

 NoSuchFrameException: Thrown when trying to switch to a frame


that does not exist.
 Example: Trying to switch to an iframe that is not present on the
page.

 InvalidElementStateException: Thrown when performing an action


on an element that is not possible.
 Example: Entering text into a disabled text field.

 WebDriverException: A general exception that is thrown when


something goes wrong while interacting with WebDriver.
 Example: A failure in initializing WebDriver.

 JavascriptException: Thrown when there is an issue executing


JavaScript via Selenium’s executeScript method.
 Example: Executing an invalid JavaScript function.

 ElementClickInterceptedException: Thrown when an element is


clicked, but another element obstructs the click.
 Example: A modal dialog is blocking a button from being clicked.

 NoAlertPresentException: Thrown when trying to switch to an


alert, but no alert is present.
 Example: Attempting to handle a JavaScript alert that hasn’t
appeared yet.

 MoveTargetOutOfBoundsException: Thrown when trying to move


the mouse to an area outside the viewable document or screen.
 Example: Interacting with elements that are off the visible part of the
webpage.
SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

 SessionNotFoundException: Thrown when attempting to interact


with a browser session that has been closed or not initialized.
 Example: When trying to perform actions after closing the browser
window.

 InvalidSelectorException: Thrown when a selector used to find an


element is invalid.
 Example: Using an incorrect XPath or CSS selector syntax.

 ElementNotSelectableException: Thrown when an element is


present but cannot be selected.
 Example: Attempting to select an element that is disabled.

 NoSuchAttributeException: Thrown when an attribute of an


element is not found.
 Example: Trying to access a non-existent attribute of an element.

 UnhandledAlertException: Thrown when there is an unhandled


alert present, and the WebDriver is unable to perform any action.
 Example: Trying to click an element while an alert box is open.

 InvalidArgumentException: Thrown when an invalid argument is


passed to a command.
 Example: Providing incorrect parameters to a WebDriver method.

 ImeNotAvailableException: Thrown when input method editor


(IME) support is not available.
 Example: This can occur in mobile automation when IME is required
but unavailable.
SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

 ImeActivationFailedException: Thrown when activating the IME


engine fails.
 Example: Happens when trying to activate an input method editor
on certain devices during mobile testing.

 NotFoundException: A general exception class that is the parent of


various specific "not found" exceptions such as
NoSuchElementException, NoSuchFrameException, etc.
 Example: It can be used when specific exceptions are not detailed
enough.

 NoSuchSessionException: Thrown when WebDriver is used after


the session is closed or does not exist.
 Example: If you try to interact with WebDriver after calling
driver.quit.

 InvalidCoordinatesException: Thrown when the coordinates


provided to an action (like mouse movement) are invalid.
 Example: Providing coordinates outside the bounds of the current
screen.

 UnhandledCommandException: Thrown when the requested


command is not recognized by the WebDriver server.
 Example: When an invalid or unknown command is sent to the
WebDriver.

 NoSuchCookieException: Thrown when trying to access a cookie


that doesn’t exist.
 Example: Attempting to retrieve or delete a cookie that is not set in
the browser.
SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

 InsecureCertificateException: Thrown when navigating to a site


with an insecure SSL certificate.
 Example: This happens when WebDriver is unable to verify the SSL
certificate of a website.

 UnexpectedTagNameException: Thrown when a WebElement is


not of the expected tag type.
 Example: Attempting to select an option from a dropdown, but the
WebElement is not a select tag.

 InvalidCookieDomainException: Thrown when trying to set a


cookie on a different domain than the current URL.
 Example: Trying to add a cookie for a domain that doesn’t match the
current website’s domain.

 ScreenshotException: Thrown when WebDriver fails to capture a


screenshot.
 Example: This can happen if the browser window is not visible or
minimized.

 ElementNotInteractableException: Thrown when an element is


found but is not in a state that can be interacted with.
 Example: Trying to click a button that is disabled or off-screen.

 UnsupportedCommandException: Thrown when the WebDriver


command is not supported by the browser.
 Example: Attempting to use a command that is not implemented by
the current browser driver.
SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

 RemoteDriverServerException: Thrown when an error occurs on


the remote WebDriver server.
 Example: This happens when using Selenium Grid or remote
WebDriver and the server encounters an issue.

 InvalidSessionIdException: Thrown when the session ID is invalid


or the session has expired.
 Example: This happens if you try to interact with a session after it
has been terminated.

 UnsupportedOperationException: Thrown when an operation is


not supported.
 Example: Attempting to perform an unsupported operation on a
particular WebElement or browser.

 NoSuchContextException: Thrown when the context to be switched


to is not available.
 Example: When trying to switch between different application
contexts in mobile automation (Appium).

 InvalidSelectorException: Thrown when a selector is invalid or


unsupported.
 Example: Using an incorrect CSS or XPath selector.

 ElementClickInterceptedException: Thrown when an element click


command could not be completed as the click is intercepted by
another element.
 Example: Trying to click on an element but another element like an
advertisement or modal is covering it.
SELENIUM WEBDRIVER EXCEPTIONS WITH EXAMPLE

 ErrorHandler.UnknownServerException: Thrown when the server


responds with an error that WebDriver doesn't know how to handle.
 Example: Encountering an unhandled error from the browser or
WebDriver server.

 InvalidArgumentException: Thrown when an argument sent to a


command is invalid.
 Example: Passing invalid parameters to a WebDriver method, such
as a negative timeout value.

You might also like