title: Selenium how to get all elements inside a WebElement
body: <p>I'm trying to get all the elements inside a selenium <code>WebElement</code>, for example:</p>
  <pre><code>&lt;div&gt;
      &lt;element&gt;
          &lt;header&gt;header&lt;/header&gt;
          &lt;p&gt;Paragraph&lt;/p&gt;
      &lt;/element&gt;
      &lt;element&gt;
          &lt;p&gt;Another Paragraph&lt;/p&gt;
      &lt;/element&gt;
  
  &lt;/div&gt;
  </code></pre>
  <p>I want to get a list of all the elements inside  including child elements, like so...</p>
  <ol>
  <li>div</li>
  <li>element</li>
  <li>header</li>
  <li>paragraph</li>
  <li>element</li>
  <li>paragraph</li>
  </ol>
  <p>So I've tried this</p>
  <p><code>element.findElements(By.xpath(&quot;*&quot;))</code></p>
  <p>but this would return only</p>
  <ol>
  <li>element</li>
  <li>element</li>
  </ol>
  <p>So then I tried a recursive method to get all of the childs</p>
  <pre><code>private static ArrayList&lt;WebElement&gt; getAllElements(WebElement element, ArrayList&lt;WebElement&gt; ret) {
      ret.add(element);
      List&lt;WebElement&gt; childs = element.findElements(By.xpath(&quot;*&quot;));
      for(WebElement e: childs)
          getAllElements(e,ret);
      return ret;
  }
  private static List&lt;WebElement&gt; getAllElements(WebElement element) {
     return getAllElements(element,new ArrayList&lt;WebElement&gt;());
  }
  </code></pre>
  <p>But querying <code>findElements()</code> takes too long</p>
  <p>I'm thinking there must be a <code>xpath</code> way, but I can't seem to find it</p>