title: Locating child nodes of WebElements in selenium
body: <p>I am using selenium to test my web application and I can successfully find tags using <code>By.xpath</code>. However now and then I need to find child nodes within that node.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;div id="a"&gt;
      &lt;div&gt;
          &lt;span /&gt;
          &lt;input /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I can do:</p>
  
  <pre><code>WebElement divA = driver.findElement( By.xpath( "//div[@id='a']" ) )
  </code></pre>
  
  <p>But now I need to find the input, so I could do:</p>
  
  <pre><code>driver.findElement( By.xpath( "//div[@id='a']//input" ) )
  </code></pre>
  
  <p>However, at that point in code I only have <code>divA</code>, not its xpath anymore... I would like to do something like this:</p>
  
  <pre><code>WebElement input = driver.findElement( divA, By.xpath( "//input" ) );
  </code></pre>
  
  <p>But such a function does not exist.
  Can I do this anyhow?</p>
  
  <p>BTW: Sometimes I need to find a <code>&lt;div&gt;</code> that has a certain decendent node. How can I ask in xpath for "the <code>&lt;div&gt;</code> that contains a <code>&lt;span&gt;</code> with the text <code>'hello world'</code>"?</p>