title: Understanding WebElement.findElement() and XPATH
body: <p>I want to use the <code>WebElement.findElement()</code> API to locate a node inside the parent node using XPATH <code>//span[@class='child-class']</code>. I thought this would return me the <code>&lt;div&gt;</code> that is inside the parent. However, it is returning me the first one it found in the entire DOM tree. Did I use the wrong XPATH?</p>
  
  <p>I have also tried using <code>.//span[@class='child-class']</code> as the XPATH, but that does return anything.</p>
  
  <p>Thank you.</p>
  
  <p>UPDATE:</p>
  
  <p>given the HTML below, I want to define a locator for the child-title <code>&lt;span&gt;</code> and child-date <code>&lt;span&gt;</code> and locate them using WebElement.findElement() API regardless of the parent being "//a/li[1]" or "//a/li[2]"</p>
  
  <pre><code>&lt;a&gt;
      &lt;li&gt; parent 1
          &lt;div&gt;
              &lt;span class="child-title child-style"&gt;title 1&lt;/span&gt;
              &lt;span class="child-date child-style"&gt; date 1&lt;/span&gt;
              &lt;span class="child-author"&gt;author 1&lt;/span&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  &lt;/a&gt;
  &lt;a&gt;
      &lt;li&gt; parent 2
          &lt;div&gt;
              &lt;span class="child-title child-style"&gt;title 2&lt;/span&gt;
              &lt;span class="child-date child-style"&gt; date 2&lt;/span&gt;
              &lt;span class="child-author"&gt;author 3&lt;/span&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  &lt;/a&gt;
  &lt;a&gt;
      &lt;li&gt; parent 3
          &lt;div&gt;
              &lt;span class="child-title child-style"&gt;title 3&lt;/span&gt;
              &lt;span class="child-date child-style"&gt; date 3&lt;/span&gt;
              &lt;span class="child-author"&gt;author 3&lt;/span&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>I have a <code>WebElement parent2</code> initialized and located using <code>"//a/li[2]"</code>, </p>
  
  <p><code>WebElement child = parent2.findElement(By.xpath("//span[@class='child-author']"));</code> would give me "author 1"</p>
  
  <p><code>WebElement child = parent2.findElement(By.xpath("span[@class='child-author']"));</code> would give me <code>NoSuchElementException</code></p>