title: How to iterate thru table to find all values
body: <p>I am attempting to extract and print all values associated with @class='Grp' attribute.  According to HTML, this attribute appears twice within table.  Using my code, I can find and print Text 1 value, but I cannot get Text 2 value.  I think for loop is the problem, but not sure how to fix.</p>
  
  <pre><code>WebElement table = driver.findElement(By.id("Table"));
  WebElement tbody = table.findElement(By.tagName("tbody"));
  WebElement tr = tbody.findElement(By.tagName("tr"));
  List&lt;WebElement&gt; rows = tr.findElements(By.tagName("td"));
  logger.info("number of rows: " +rows.size());
  ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
  
  for (int i=0; i&lt;rows.size();i++)    
      {
          WebElement heading = table.findElement(By.xpath("//*[@class='Grp']"));
          if (heading.getText().trim().contains("Text"))
              { 
                  logger.info("text: " +heading.getText().trim());
                  list.add(heading.getText().trim());
              }
  </code></pre>
  
  <p>Html</p>
  
  <pre><code>&lt;table id="Table" width="100%" cellspacing="0" cellpadding="0" border="0"&gt;
  &lt;thead class="Head"&gt;
  &lt;tbody&gt;
  &lt;tr style="height:30px"&gt;
  &lt;td class="Grp" style="background-color:#686890;white-space:nowrap" colspan="99"&gt;Text 1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tbody&gt;
  &lt;tr style="height:30px"&gt;
  &lt;td class="Grp" style="background-color:#686890;white-space:nowrap" colspan="99"&gt;Text 2&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>