for loop "index was out of range" c# webdriver -
i getting "index out of range" loop. need use new elements loop founds, how do that? please fix problem
int linkcount = driver.findelements(by.cssselector("a[href]")).count; string[] links = new string[linkcount]; (int = 0; < linkcount; i++) { list<iwebelement> linkstoclick = driver.findelements(by.cssselector("a[href]")).tolist(); links[i] = linkstoclick[i].getattribute("href"); }
i think refactor code:
var linkelements = driver.findelements(by.cssselector("a[href]")).tolist(); var links = new list<string>(); foreach (var elem in linkelements) { links.add(elem.getattribute("href")); }
if works, simplify query:
var instantlinks = driver.findelements(by.cssselector("a[href]")) .select(e => e.getattribute("href")) .tolist();
Comments
Post a Comment