title: Webdriver - Find first x elements with same class
body: <p>Can someone help me in following issue:
  I have page with a lot of <strong>li</strong> elements, as shown below:</p>
  
  <pre><code>&lt;ul class="feed-tips" id="Grid" data-sport="" data-country="" data-league=""&gt;
  &lt;li class="feed-item vevent tip-list-row" data-sort-bookmaker="12" data-sort-datetime="1525849200" data-sort-match="1" data-sort-odds="1.80" data-sort-rating="3" data-sort-status="1" data-sort-yield="-2.106" data-tip-id="6900510"&gt;
  &lt;li class="feed-item vevent tip-list-row" data-sort-bookmaker="22" data-sort-datetime="1525852800" data-sort-match="2" data-sort-odds="2.59" data-sort-rating="2" data-sort-status="1" data-sort-yield="-3.082" data-tip-id="6900483"&gt;
  &lt;li class="feed-item vevent tip-list-row" data-sort-bookmaker="22" data-sort-datetime="1525852800" data-sort-match="3" data-sort-odds="2.21" data-sort-rating="2" data-sort-status="1" data-sort-yield="-4.118" data-tip-id="6899865"&gt;
  </code></pre>
  
  <p>Inside that <strong>li</strong> list each element has following class:</p>
  
  <pre><code>&lt;span class="original-language-image flag-icon flag-icon-gb"&lt;/span&gt;
  </code></pre>
  
  <p>All <strong>li</strong> elements have that <strong>span</strong> class, and only difference is instead above shown <strong>-gb</strong>, it is different country code.</p>
  
  <p>I have to find first <strong>n</strong> elements with same <strong>gb</strong> code (and also those elements has to be one after another), and compare if is same as first element. Rest with different code, I do not need.</p>
  
  <p>Tried with following code but did something wrong (or made mistake by using <strong>equals</strong> in <strong>if</strong> statement):</p>
  
  <pre><code>List&lt;WebElement&gt; tipsGB = driver.findElements(By.xpath("//ul[@class='feed-tips']/li/div[@class='author medium-3 small-12 column padding-reset tip-list-row__author']\n"
              + "//div[@class='original-tip-language-container']/span[contains(@class,'flag-icon-gb')]"));
      WebElement firstTip = tipsGB.get(0);
      for (int p = 1; p &lt; tipsGB.size(); p++) {
          System.out.println(tipsGB.get(p));
          WebElement nextTip = tipsGB.get(p);
          if (nextTip.equals(firstTip)) {
              WebElement tipLink = nextTip.findElement(By.xpath("../../../..\n"
                      + "/div[@class='tip medium-9 small-12 column padding-reset dtstart tip-list-row__tip']\n"
                      + "/div[@class='tip-match medium-12 column']/div[@class='tip-teams']/a"));
              System.out.println("Link to a tip with same language is: " + tipLink.getAttribute("href"));
          } else {
              System.out.println("No more tips in same language on top of page");
              continue;
          }
      }
  </code></pre>
  
  <p>Thank you in advance</p>