【发布时间】:2012-02-08 20:07:19
【问题描述】:
我有一个带有唯一 ID 的 div。在div 之下是一堆span 元素,它们具有className=foo。 className=foo 有几个 span 元素,但它们对于每个 div 都是唯一的(如果很清楚的话)。因此,我的 Selenium 代码首先将唯一的 div 作为 Web 元素获取,然后尝试获取该元素并通过类名获取 span,就像这样
element = sDriver.findElement(By.id("c_"+cID));
String sTest = element.findElement(By.className("actions")).getText();
在第二行它每次都会抛出一个异常
org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 22 milliseconds
我是否误解了如何从唯一的 div 下获取 span?
【问题讨论】:
标签: selenium webdriver selenium-webdriver