In this post, we will study the most commonly encountered exceptions in Selenium WebDriver and the root cause of these exceptions.
Reason - In case no element could be located from the locator provided.
Resolution - Check the correctness of the locators for the elements and make sure that the element is present when interacted with.
Reason - In case element is present in the dom but is not visible.
Resolution - Make sure that the element is in the visible area when interacted with. Some common methods to acheive this are - maximizing the browser window, scrolling to the element.
Reason - In case we try to switch to an alert but the targetted alert is not present.
Resolution - Make sure that alert is present when it is interacted with.
Reason - In case we try to switch to a frame but the targetted frame is not present.
Resolution - Check the frame locators and make sure frame is present on the webpage.
Reason - In case we try to switch to a window but the targetted window is not present.
Resolution - Get the list of window handles using driver.getWindowHandles() and switch to one of the handles present at that particualr time.
Reason - In case an unexpected alert blocks normal interaction of the driver.
Resolution - Accept or dismiss the alert to continue interacting with the dom.
Reason - In case a command execution gets timeout.
Resolution - This may be a valid exception unless we have set very low timeout values in implicit and explicit waits.
Reason - In case the state of an element is not appropriate for the desired action.
Resolution - Make sure that the element is available to perform the desired operation by waiting for the desired ExpectedCondition in explicit wait.
Reason - In case we are trying to fetch an attribute's value but the attribute is not correct.
Resolution - Just make sure the attribute we want to fetch from an element is actually present in th element or not.
Reason - In case there is some issue with driver instance preventing it from getting launched.
Resolution - Check the driver's instantiation and the dependecies required to instantiate the driver object.