尝试单击元素时出现StaleElementReferenceException

时间:2017-03-20 06:27:31

标签: java selenium selenium-webdriver

我正在使用Selenium实施Java测试。但是,由于StaleElementReferenceException,我的测试失败。我正在执行以下操作

driver.get(URL);
List<WebElement> Anchors = driver.findElements(By.xpath("//div[not(contains(@style,'display:none'))]/a"));

//same URL again

driver.get(URL);
Anchors.get(0).click();

当我尝试单击Anchors列表中的任何元素时,我收到错误。

1 个答案:

答案 0 :(得分:0)

每当DOM更改或刷新时,即使您仍然在同一页面中,驱动程序也会丢失&#34;它之前找到的WebElements,您获得StaleElementReferenceException。如果您确实需要在单击之前再次使用driver.get(URL);,则需要重新定位列表。

相关问题