我正在使用 Selenium 2/WebDriver 进行自动化。我有一张桌子,正在尝试在其中选择一行。当测试运行时,我可以看到该行变得突出显示,就像它被单击一样,但随后我立即收到"org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM"错误并且测试失败。
代码如下:
@Test
public void rowSelection() throws Exception
{
    SeleniumHelper helper = new SeleniumHelper();
    action = new SeleniumActionHelper(driver);
    helper.login();
    String testUrl = navigateToUrl("option/listOptions.xhtml");
    driver.get(testUrl);
    WebElement table = findElementById("tableSection:dataTableWrapped_data");
    List<WebElement> allRows = table.findElements(By.tagName("tr"));
    for (WebElement row : allRows)
        {
            List<WebElement> cells = row.findElements(By.tagName("td"));
            for (WebElement cell : cells)
            {
                WebElement listName = cell.findElement(By.xpath("./* [text()='body_build']"));
                listName.click();
            }
        }
}
我Thread.sleep(2000)在动作前后都放了一个listName.click(),但都没有帮助。任何帮助将不胜感激。