title: Java selenium xpath - getting all elements under a specific element
body: <p>this is a simplified HTML structure i'm searching through:</p>
  
  <pre><code>&lt;div class="main"&gt;
  ...other stuff...
         &lt;td class="child"&gt;44&lt;/td&gt;
         &lt;td class="child"&gt;59&lt;/td&gt;
         &lt;td class="child"&gt;11&lt;/td&gt;
  &lt;/div&gt;
  &lt;div class="main"&gt;
  ...other stuff...
         &lt;td class="child"&gt;5&lt;/td&gt;
         &lt;td class="child"&gt;14&lt;/td&gt;
         &lt;td class="child"&gt;98&lt;/td&gt;
  &lt;/div&gt;
  ...this kind of structure repeats with similar numbers a few more times but with identical class names
  </code></pre>
  
  <p>I need to extract all the numbers under the first found main class so I've made a query to search for the first main, and all td's with the specific class under it. Can somebody give me a hint what I'm doing wrong since this query gives me all the numbers from all td's with class "child" in all "main" div's:</p>
  
  <pre><code>List&lt;WebElement&gt; koefi = driver.findElements(By.xpath("//div[@class='main'][1]//td[@class='child']"));
  </code></pre>
  
  <p>What am I doing wrong or is my logic right but I'm missing some other parts of html which I haven't pasted here since the structure is too cumbersome..?</p>
  
  <p>Thank You!!</p>
  
  <p>p.s.:
  I tried this also but again, I get contents of all td's with "child" class, and not only the first "main"..</p>
  
  <pre><code>List&lt;WebElement&gt; koefi = driver.findElements(By.xpath("//*[1][@class='main']//td[@class='child']"));
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  I managed to solve my problem by first getting the first occurence of the "main" div which is by default found by the .findElement function:</p>
  
  <pre><code>WebElement element = driver.findElement(By.xpath("//*[1][@id='main']"));
  </code></pre>
  
  <p>And then extracting with .findElements function the "child" classes:</p>
  
  <pre><code>List&lt;WebElement&gt; kk = element.findElements(By.className("child"));
  </code></pre>
  
  <p>I am still unable to figure out why doesn't the .findElements with my xpath work, or it works too well, it extracts every "main" class and not only the first one. And the original HTML is too big to paste here, so I don't want to bother you guys!!</p>