- Jan 20, 2019
- admin
- 0
StaleElementReferenceException
As the name indicates, it occurs as element is stale now. If the WebDriver throws this exception that means, the reference for this element is lost but the element is present in the DOM.
This happens when user performs certain action on the webpage (like clicking a button), which leads to refreshing the DOM
Following solutions will help in getting rid of this exception:
Solution 1:
If you use driver.FindElement() after the DOM is refreshed instead of recognizing the element before.
Solution 2:
If you are using Page Factory/Page Object Model, you have to instantiate the elements again as given below:
PageFactory.InItElements(driver, page);
This will initialize all the UI Objects of the page again after the DOM is refreshed. Hope this helps.
Happy Testing!!!