IWebElement table = driver.FindElement(By.ClassName("mozaique"));
IList<IWebElement> list = table.FindElements(By.ClassName("thumb-block "));
foreach (var item in list)
{
item.Click();
driver.FindElement(By.CssSelector("span.icon.download")).Click();
waitforDWNlink();
driver.Navigate().Back();
driver.Navigate().GoToUrl(URL);
}
The first time when I'm going through the foreach
loop it works fine. Inside the foreach
loop I navigate to another page. After that, when iterating again in the foreach
loop, it gives me an exception.
What am I doing wrong?
EDIT: After seeing one of the answers I tried this:
IWebElement table = driver.FindElement(By.ClassName("mozaique"));
IList<IWebElement> list = table.FindElements(By.ClassName("thumb-block "));
List<string> NewList= new List<string>();
foreach (var item in list)
{
NewList.Add(item.GetAttribute("href"));
}
I was trying to store the href
on a new list item.But after running the code ,the new list item was blank.