I keep getting this exception in Selenium ...
OpenQA.Selenium.StaleElementReferenceException: 'stale element reference: element is not attached to the page document (Session info: chrome=60.0.3112.113) (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.15063 x86_64)'
This is insanely frustrating and I can't understand why I get the exception thrown in the return statement inside the BuildOrg method below.
Here's the code that triggers the problem ...
for (int i = 0; i <= lastPage; i++)
{
orgs.AddRange(
browser
.FindElement(By.Id("all_organizations"))
.FindElement(By.TagName("tbody"))
.FindElements(By.TagName("tr"))
.Select(e => BuildOrg(e))
);
browser
.FindElement(By.Id("all_organizations_next"))
.FindElement(By.TagName("a"))
.Click();
}
.....
Organisation BuildOrg(IWebElement orgElement)
{
var cells = orgElement.FindElements(By.TagName("td"));
var avatarUrl = cells[0].FindElement(By.TagName("img")).GetAttribute("src");
var c = DateTimeOffset.Parse(cells[2].Text);
return new Organisation
{
Id = int.Parse(avatarUrl.Split('_')[1].Split('/')[0]),
Avatar = avatarUrl,
Name = cells[1].Text,
Link = cells[1].FindElement(By.TagName("a")).GetAttribute("href"),
CreatedOn = c
};
}
Can any lend any light on this?