I am getting an error while running my selenium tests
Exception in thread "main"
org.openqa.selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.34.522932 (
4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.12.6
x86_64) (WARNING: The server did not provide any stacktrace
information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/stale_element_reference.html
01T19:05:14.666Z'.
Here is the code
List<WebElement> category =
driver.findElements(By.className("a2s-skill-block"));
for(int i = 0;i<category.size();i++) {
category.get(i).click();
Thread.sleep(7000);
driver.navigate().back();
// WebElement skills1 = driver.findElement(By.id("iApps"));
//skills1.click();
Thread.sleep(15000);
}
I went through similar thread posts on this question and tried a lot of solutions mentioned by fellow members but somehow the wait and Expected COnditions don't seem to work.Any other direction of thought is really appreciated.
These are the options I tried
- Increased the wait time through Thread.sleep() method
Introduced wait and Expected Conditions
WebDriverWait wait = new WebDriverWait(driver, 150);
wait.until(ExpectedConditions. presenceOfAllElementsLocatedBy(By.className("text-heading")));