I am using Selenium 2/WebDriver for automation. I have a table and am trying to select a row in it. When the test runs, I can see the row become highlighted as if it is clicked, but then immediately I get the "org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM"
error and the test fails.
The code is the following:
@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();
}
}
}
I have put a Thread.sleep(2000)
in front and after the listName.click()
action, but neither has helped. Any help would be greatly appreciated.