0% found this document useful (0 votes)
19 views4 pages

Exceptions in Selenium 1729655751

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 views4 pages

Exceptions in Selenium 1729655751

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/ 4

EXCEPTIONS IN SELENIUM

1. NoSuchElementException

Description: Raised when Selenium is unable to find an element on the page.

Cause: Occurs when an element with the specified locator is not present in the DOM.

Solution: Double-check the element locator (ID, class, XPath, etc.). You may also need to use

waits to allow time for the element to load.

2. ElementNotVisibleException

Description: Thrown when an element is found in the DOM but is not visible on the page,

preventing interaction.

Cause: The element might be hidden via CSS (e.g., `display: none` or `visibility: hidden`).

Solution: Ensure the element is visible before interacting with it, or use JavaScript to interact

with hidden elements.

3. StaleElementReferenceException

Description: Raised when an element is no longer attached to the DOM.

Cause: This can happen if the element is refreshed or the page DOM is updated while a script

is executing.

Solution: Refetch the element after the DOM update or add waits to ensure the DOM is stable

before interacting with elements.

4. TimeoutException

Description: Thrown when a command takes longer than the specified wait time to complete.
Cause: Occurs when a WebDriver wait command (implicit or explicit) does not locate the

element within the specified timeout.

Solution: Increase the wait time or optimize the condition to check element’s visibility.

5. NoSuchFrameException

Description: Thrown when the frame being switched to does not exist.

Cause: Occurs when trying to switch to a frame that is not found by the specified name or ID.

Solution: Check the frame’s name or ID, or ensure the frame is present before attempting to

switch to it.

6. NoAlertPresentException

Description: Raised when attempting to interact with an alert that is not present.

Cause: Occurs when `switchTo().alert()` is used, but there is no alert currently on the page.

Solution: Ensure the alert is present before switching to it. Use waits if necessary.

7. ElementNotSelectableException

Description: Thrown when an element is present in the DOM but cannot be selected.

Cause: Occurs with elements like `select` dropdowns where an option cannot be selected.

Solution: Ensure the element is selectable, or use JavaScriptExecutor to force selection .

8. InvalidElementStateException

Description: Raised when trying to perform an action on an element that is not in a state where
it can be interacted with.

Cause: Occurs if you try to enter text into a disabled text field or click on a disabled button.

Solution: Verify that the element is enabled before interacting with it.
9. WebDriverException

Description: A generic exception that occurs when the WebDriver is performing an action or

command that causes an unexpected issue.

Cause: Can happen due to browser driver issues, WebDriver server errors, or connection

problems.

Solution: Check for issues with the WebDriver installation or compatibility between the

WebDriver version and browser.

10. MoveTargetOutOfBoundsException

Description: Thrown when attempting to move the mouse to an element or coordinate that is

outside the viewable area of the webpage.

Cause: The element might be off-screen or not in the visible viewport.

Solution: Scroll the element into view using JavaScript before interacting with it.

11. InvalidSelectorException

Description: Raised when an invalid selector is used in a `findElement` or `findElements`

method.

Cause: Occurs when an invalid XPath, CSS selector, or another locating strategy is used.

Solution: Double-check the selector syntax and ensure it is valid.


12. SessionNotFoundException

Description: Thrown when the WebDriver session is either deleted or is no longer active.

Cause: Can occur if the WebDriver instance is closed or quit prematurely.

Solution: Make sure the session is active before performing any further actions.

13. InvalidArgumentException

Description: Raised when an invalid argument is passed to a command.

Cause: Occurs when invalid parameters are passed to WebDriver methods.

Solution: Ensure that the method arguments are valid and properly formatted.

14. UnsupportedCommandException

Description Thrown when a command is unsupported by the current browser or WebDriver

version.

Cause Occurs when trying to use a command that is not available for the current WebDriver or

browser.

Solution Check the WebDriver documentation and ensure the command is supported by the

browser.

You might also like