Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
if(elements.size()>0)
{
for(WebElement str: elements)
{
FirstLink.click();
wait = new WebDriverWait(driver,30);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//Second link
driver.findElement(By.partialLinkText("employees on LinkedIn")).click();
Thread.sleep(3000);
//Going to 2 screens back
((JavascriptExecutor) driver).executeScript("window.history.go(-2)");
}
}