Selenium: How to handle Stale Element Exception error

Common Causes
A stale element reference exception is thrown in one of two cases:
  1. The element has been deleted entirely or element/page  has been refreshed
  2. The element is no longer attached to the DOM.

  1. The most simple solution is to use the Java PageFactory, this will create a proxy WebElement that will find the element every time you use it (There is a slim change that the element will be released in the couple of milliseconds between it being found and you performing an action on it, in this case it is suggested to use an explicit wait to wait for the element to become stale before finding it again).
  2. Use try catch to handle this exception and reload the element in catch block.
  3. Add a short sleep between FindElement & action method..


Popular posts from this blog

Testing Webservice with SoapUI Having Windows Authentication

Data Driven Testing Using Selenium -WebDriver in Python

How to Re-run Failed Scenarios in Cucumber