I am trying unsuccessfully to change the following loop to a LINQ expression:
int index = 0;
IList<IWebElement> divNota = new List<IWebElement>();
foreach (IWebElement element in tablaNotas)
{
divNota.Add(element.FindElement(By.Id("accion-1-celda-0-" + index + "-0")));
index++;
}
I tried using
IList <IWebElement> divNota = tablaNotas.Select(element => element.FindElement(By.Id("accion-1-celda-0-"+ tablaNotas.IndexOf(element) + "-0"))).ToList();
But tablaNotas.IndexOf(element)
always returns -1
, meaning the element
was not found inside tablaNotas
.
The string "accion-1-celda-0-"+ tablaNotas.IndexOf(element) + "-0"
is meant to change to
"accion-1-celda-0-"+ 1 + "-0"
"accion-1-celda-0-"+ 2 + "-0"
"accion-1-celda-0-"+ 3 + "-0"
...
"accion-1-celda-0-"+ n + "-0"
In accordance to element's index
Any help is appreciated