for loop “index was out of range” c# webdriver

后端 未结 5 657
一生所求
一生所求 2021-01-16 07:08

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         


        
5条回答
  •  被撕碎了的回忆
    2021-01-16 07:20

    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.

提交回复
热议问题