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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -