【发布时间】:2018-01-01 13:53:55
【问题描述】:
我在运行 selenium 测试时遇到错误
Exception in thread "main"
org.openqa.selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.34.522932 (
4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.12.6
x86_64) (WARNING: The server did not provide any stacktrace
information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/stale_element_reference.html
01T19:05:14.666Z'.
这里是代码
List<WebElement> category =
driver.findElements(By.className("a2s-skill-block"));
for(int i = 0;i<category.size();i++) {
category.get(i).click();
Thread.sleep(7000);
driver.navigate().back();
// WebElement skills1 = driver.findElement(By.id("iApps"));
//skills1.click();
Thread.sleep(15000);
}
我浏览了有关此问题的类似帖子,并尝试了其他成员提到的许多解决方案,但不知何故,等待和预期条件似乎不起作用。非常感谢任何其他方向的思考。
这些是我尝试过的选项
- 通过 Thread.sleep() 方法增加了等待时间
-
引入等待和预期条件
WebDriverWait 等待 = new WebDriverWait(驱动程序, 150);
wait.until(预期条件。 presentOfAllElementsLocatedBy(By.className("text-heading")));
【问题讨论】: