I have tried fluent wait but Actually Sometime run successfully and sometime's got exception like stale exception in selenium.
Asked
Active
Viewed 87 times
-2
-
See [here](https://stackoverflow.com/questions/18225997/stale-element-reference-element-is-not-attached-to-the-page-document?noredirect=1&lq=1). – Mate Mrše Sep 19 '18 at 08:18
1 Answers
0
Stale element exception arises when the element is either deleted from DOM or the element is longer attached to DOM.
You can handle through the below ways: 1).using try catch block like below:
if the element is located for the first time itself then it breaks and comes out of the loop
for(int i=0; i<=2;i++)
{
try
{
driver.findElement(By.("__")).click();
break;
} catch(StaleElementException e))
{
Sysout();
}
}
2.You can also use webdriver wait and provide your conditions like below:
WebDriverWait wait=new WebdriverWait();
wait.until(ExpectedConditions.presenceOfElementLocated(By.___());

Fury
- 142
- 1
- 12
-
I also applied these two option but getting same issue in my code. – Rajkumar Sharma Sep 18 '18 at 12:06
-
-
public void WebElement getElement(final By locator, WebDriver driver) { FluentWait
wait = new FluentWait – Rajkumar Sharma Sep 21 '18 at 08:50(driver).withTimeout(Duration.ofSeconds(100)) .pollingEvery(Duration.ofMillis(600)).ignoring(NoSuchElementException.class); WebElement element = wait.until(new Function () { @Override public WebElement apply(WebDriver arg0) { return arg0.findElement(locator); } }); return element; } -
this is my common method with fluent wait and getting sometime stale exception and some time work fine. – Rajkumar Sharma Sep 21 '18 at 08:50