I have List of URLs and I just wanted to open the URL on same browser session. To do that I have written the below code but it is throwing the error after opening the first URL i.e. second URL is not being opened.
findElements = driver.findElements(By.xpath("//*[@id='search-user-found']//p/a"));
for (WebElement webElement : findElements)
{
Thread.sleep(200);
System.out.println(webElement.getAttribute("href"));
driver.navigate().to(webElement.getAttribute("href"));
Thread.sleep(200);
}
Error:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Please assist.