Learn what is Stale Element Reference Exception in Selenium, its causes, and strategies to overcome it effectively.
00:04 - Introduction to Selenium Exceptions
00:17 - Element Click Interception Exception
00:32 - Element Not Interactable Exception
02:19 - Element Not Selectable Exception
04:16 - Element Not Visible Exception
05:53 - Insecure Certification Exception
08:24 - Unable to Set Cookie Exception
08:39 - Invalid Cookie Domain Exception
10:21 - Invalid Coordinates Exception
11:29 - Invalid Element State Exception
11:35 - Invalid Session ID Exception
12:32 - Invalid Switch to Target Exception
13:26 - JavaScript Exception
14:45 - Move Target Out of Bounds Exception
15:12 - No Alert Present Exception
16:08 - No Such Attribute Exception
17:06 - No Such Cookie Exception
18:28 - No Such Element Exception
19:02 - Invalid Selector Exception
20:04 - No Such Frame Exception
20:30 - No Such Window Exception
21:12 - Remote Driver Server Exception
21:57 - Stale Element Reference Exception
23:39 - Timeout Exception
25:01 - Unexpected Alert Present Exception
26:06 - WebDriver Quit & No Such Session Exception
27:02 - WebDriver Exception
28:01 - Unable to Locate Host Exception
29:12 - Element Not Enabled Exception
30:13 - Custom Exception Handling in Java
31:13 - Best Practices for Exception Handling
Introduction to Selenium Exceptions Selenium exceptions occur when the WebDriver fails to execute a command due to various issues like incorrect element interaction or invalid session states. Understanding these exceptions is crucial for creating stable and reliable automation tests.
Element Click Interception Exception This happens when a click action is blocked due to another overlaying element. It can be resolved by using explicit waits or ensuring the element is fully visible before clicking.
Element Not Interactable Exception Occurs when an element is present in the DOM but cannot be interacted with. Handling it involves waiting for visibility and using JavaScript executor for certain interactions.
Element Not Selectable Exception Thrown when trying to select a disabled or hidden element. The solution is to check the element’s state before attempting any interaction.
Element Not Visible Exception Occurs when an element exists in the DOM but is not visible for interaction. Using explicit waits ensures the element becomes visible before performing actions.
Insecure Certification Exception Happens when navigating to a website with invalid SSL certificates. It can be bypassed using Chrome DevTools Protocol (CDP) or browser-specific settings.
Unable to Set Cookie Exception Occurs when WebDriver fails to set a cookie due to domain mismatches. Ensuring the correct domain and using appropriate cookie management techniques can fix this.
Invalid Coordinates Exception Thrown when performing an action using incorrect screen coordinates. This can be avoided by maximizing the browser window and verifying element positions before execution.
Invalid Element State Exception Happens when an element is not in an appropriate state for interaction. It is handled by checking the element’s state before performing any operations.
Invalid Session ID Exception Occurs when trying to interact with a session that is no longer active. Proper session management and ensuring the WebDriver quits properly help prevent this.
No Such Element Exception Thrown when Selenium cannot locate an element. This can be resolved by verifying locators and using implicit or explicit waits for dynamic elements.
No Such Window Exception Occurs when attempting to switch to a window that no longer exists. Using getWindowHandles() ensures that the target window is still available.
Remote Driver Server Exception Happens due to issues with the Selenium Grid remote server. Checking server logs and configurations can help identify and fix the problem.
Session Not Created Exception Occurs when WebDriver fails to create a session due to outdated drivers or browser mismatches. Keeping drivers updated and ensuring compatibility resolves this.
Stale Element Reference Exception Happens when an element is removed from the DOM before an action is performed. The fix is to re-locate the element before executing commands.
Timeout Exception Occurs when a command takes longer than the specified time to execute. Using appropriate implicit or explicit waits helps in handling this exception.
Unexpected Alert Exception Happens when an unexpected pop-up alert appears during execution. Using try-catch blocks and handling alerts in the script can resolve this.
WebDriver Exception A general exception that occurs when WebDriver fails to execute commands. Ensuring correct browser-driver configuration and handling failures properly prevents this issue.
No Such Session Exception Occurs when commands are executed after the browser session has been closed. Managing the WebDriver lifecycle properly helps in avoiding this issue.
Custom Exception Handling in Selenium Creating well-structured exception messages improves debugging and test clarity. Formatting output messages properly helps in analyzing test failures efficiently.