When I try to locate an element I am getting an error Like StaleElementReference
using WebDriver instance I try to do driver.findelement(By.xpath(Element)) it gives back staleelementreference exception.I am using selenium java
When I try to locate an element I am getting an error Like StaleElementReference
using WebDriver instance I try to do driver.findelement(By.xpath(Element)) it gives back staleelementreference exception.I am using selenium java
The
StaleElementReferenceExceptionis thrown when you try to access a stale element usingelement.getText(),element.click(), etc. A stale element is created when you store a reference to an element on the page then either the portion of the page that contains that element or the entire page changes/reloads. The end result is that the reference you hold in your variable is pointing at nothing. If you try to access it at that point, the exception is thrown.A simple example of how to create a stale element,
The best way to avoid this issue is to be aware of and control the state of the page. If you perform an action that updates the page, make sure you refetch any variables that you stored before the page was refreshed.
To fix our simple example of a stale element,