I am getting \"index out of range\" from this loop. But I need to use new elements that loop founds, how do I do that? Please help to fix the problem
int lin
You can rewrite your code to bypass the for loop:
string[] links = driver.FindElements(By.CssSelector("a[href]")).Select(l => l.GetAttribute("href")).ToArray();
This should also avoid the index out of range problem, and cut down the amount of code you have to write.