gpt4 book ai didi

java - “StaleElementReferenceException : Element not found in the cache - perhaps the page has changed since it was looked up

转载 作者:行者123 更新时间:2023-12-01 13:24:00 25 4
gpt4 key购买 nike

我想找出页面上损坏的链接。

但是当我尝试单击第二个链接(以检查页面上损坏的链接)时,我在第二次迭代中遇到错误

StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up Command duration or timeout: 47 milliseconds"

这是我的代码:

    WebElement element =driver.findElement(By.tagName("a"));
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println(links.size());

for (int index=0; index<links.size(); index++ ) {
links.get(index).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.getTitle();
driver.navigate().back();

}

有人可以告诉我我犯了一个错误吗?

最佳答案

我认为您无法在页面上存储元素,浏览,然后返回使用它们。每次到达新页面时,您都需要再次选择它们(有点刷新)。

尝试这样的事情

   for (int index=0; index<links.size(); index++ ) {
links = driver.findElements(By.tagName("a"));
links.get(index).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.getTitle();
driver.navigate().back();
}

关于java - “StaleElementReferenceException : Element not found in the cache - perhaps the page has changed since it was looked up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21885075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com