【发布时间】:2016-02-02 17:22:54
【问题描述】:
我有 URL 列表,我只是想在同一个浏览器会话中打开 URL。为此,我编写了以下代码,但在打开第一个 URL 后抛出错误,即第二个 URL 未打开。
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);
}
错误:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
请帮忙。
【问题讨论】:
-
这是另一个非常好的、明确的答案:stackoverflow.com/a/16244739/954442