如何解决selenium异常:StaleElementReferenceException:在缓存中找不到元素

fed*_*lov 3 selenium

我正在收集链接.然后我点击第一个链接,做一些事情,向后移动(driver.navigate().back();),获得第二个链接,然后link.click();抛出异常org.openqa.selenium.StaleElementReferenceException: Element not found in the cache.
我究竟做错了什么?

pre*_*sto 5

一旦离开页面,元素变量就会变为无效.诀窍是找到第一个元素,单击,返回然后找到第二个元素并单击.