title: Clicking all elements found in List<WebElement>
body: <p>I am trying to click all of the instances of an element found by the class attribute found in an i tag within an anchor tag in the row of a dynamic table. Specifically, its a row with several cells and in the last cell there is a series of 4 links with either and X or an O. If the square is an X, it can be clicked and after a short wait, changes to an O. The links are written as follows:</p>
  
  <pre><code>&lt;a class="foobar"&gt;&lt;i class="dontNeedToClick"&gt;&lt;i&gt;&lt;/a&gt;
  &lt;a class="foobar"&gt;&lt;i class="dontNeedToClick"&gt;&lt;i&gt;&lt;/a&gt;
  &lt;a class="foobar"&gt;&lt;i class="needToClick"&gt;&lt;i&gt;&lt;/a&gt;
  &lt;a class="foobar"&gt;&lt;i class="dontNeedToClick"&gt;&lt;i&gt;&lt;/a&gt;
  </code></pre>
  
  <p>When the needToClick element is clicked, the class would change to a dontNeedToClick element There are less than a hundred X's in a database of thousands of O's to scroll through, so something to automate clicking them would save a lot of time. I can successfully count the instances the element appears in the table, but when I put the elements into a List object using .findElements() and attempt to iterate through it, I get ElementNotVisibleException.</p>
  
  <p>Here is my sample code so far:</p>
  
  <pre><code>// get the count of thumbs down accounts
      int elementsCount= driver.findElements(By.className("needToClick")).size();
      System.out.println("Amount of elements: " + elementsCount);
  
  // loop and click through all elements found
  
      for (int x = 0; x &lt; elementCount; x++) {
          List&lt;WebElement&gt; elements = driver.findElements(By.className("needToClick"));
          WebElement client = elements.get(x);
          client.click();
          Thread.sleep(5000);
      }
  </code></pre>
  
  <p>I have tried using Iterator and get the same exception thrown at me.</p>
  
  <pre><code>        Iterator&lt;WebElement&gt; clickElement = elements.iterator();
          while (clickElement.hasNext()) {
              clickElement.next().click();
          }
  </code></pre>
  
  <p>I have also tried using a foreach loop.</p>
  
  <pre><code>    List&lt;WebElement&gt; thumbsDown = driver.findElements(By.className(expectedClass));
  
      for(WebElement element : thumbsDown) {
          element.click();
      }
  </code></pre>
  
  <p>I would use xpath but I am not very experienced with dynamic tables and haven't been able to find an approach that would fetch the row containing the element I'm looking for and other elements relative to it and figured a less than elegant approach such as just finding all the elements by the class name would suffice. Would appreciate any help.</p>