Selenium – StaleElementReferenceException



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!!!

Tags: ,
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18