I have a problem when trying to find many elements in a page. Basically i have 20 identical pages, with slightly different data. Think 20 excel sheets. Page 1 50rows, page 2 100 rows, etc.. each row contains link and some data, and i want to find and make a list of all those links. So i go to page 1, get all links, move on to page 2, page 3, then when im at page which contains lots of rows, it (test) freezes, page stays open forever and there are no errors.

Im pretty sure problem is with FindElements() since this method i use to get links from each sheet/page and it works for ones with fewer elements:

        List<IWebElement> _links = new List<IWebElement>();

        List<string> links = new List<string>();

        links = d.FindElements(By.PartialLinkText(partialLink)).ToList();

        int i = 0;

        foreach (IWebElement element in _links)

It works flawlessly when there are 10-40 rows, sometimes fail at 70 rows, and can never get past 'sheet' with 400 rows. If there was problem with code it would fail sooner i think.

What is the limit to FindElements ? Could it fail/freeze and throw no errors ?

  • How about the RAM and processing power of the PC which this script running on.And have you ever try this on firefox browser ?
    – ChathuD
    Jan 13, 2017 at 17:37
  • Are you using implicit waits? It is usually set when you define your driver.
    – kirbycope
    Jan 15, 2017 at 1:21

2 Answers 2


some points before:

  1. Why use a list of IWebELements instead of WebElements?
  2. d.FindElements return a List<WebElements>. Is it necessary the ToList() at the end? And why return it to list 'link' that is a List of strings? You can do:

    List <WebElements> links = d.FindElements(By.PartialLinkText(partialLink));

3.What is the _sellerLinks? And in the foreach you can do (the 'int i' is not necessary):

foreach (IWebElement element in _sellerLinks)

[EDITED] It's hard to say but I think that the correct code you want is:

List<IWebElement> _links = d.FindElements(By.PartialLinkText(partialLink)).ToList();

List<string> links = new List<string>(); 

foreach (IWebElement element in _links)
  • 1
    code is not the problem, as i said, it works correctly when there are 10-40 elements found.
    – George
    Jan 13, 2017 at 16:56
  • IWebElements and .ToList() because of C#, _sellerLinks because i forgot to rename when pasting here. Counter works too, but if its possible to go without, i guess its better, thanks.
    – George
    Jan 13, 2017 at 17:03
  • Understood. I made a change inside my foreach that was wrong too and now is correct. Are you using this as a function that return 'links'? Jan 13, 2017 at 17:12

try to keep a temporary array on the class level and for each 50 records or for a each page, put the values to the array and clean the links and _links variable. Then start again from the 2nd page.

I never came up with this kind of situation hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.