How do I return combination of same level nodes in one webelement in selenium?
<p>my knowledge of selenium at this point is a bit limited, but from what I understand driver.find_elements_by_xpath() returns a list of webelements. One can then iterate over the elements and do whatever one wants, like printing text.
That part is easy. 
But now assume on a given page I would be looking for every combination of 3 nodes:</p>

<pre><code>&lt;parent&gt;
   &lt;h1&gt;text&lt;/h1&gt;
   &lt;div class="identifier"&gt;more stuff&lt;/div&gt;
   &lt;h3&gt;text2&lt;/h3&gt;
   &lt;h1&gt;other text&lt;/h1&gt;
   &lt;div class="identifier"&gt;other more stuff&lt;/div&gt;
   &lt;h3&gt;other text2&lt;/h3&gt;
   ...
&lt;/parent&gt;
</code></pre>

<p>These 3 nodes (here h1, div with class, and h3) are on the same level of hierarchy and there are many of them there since its a list. Is there a way to have selenium return them "packaged"? In this case I could make sure I get the correct data together. The way I am doing it right now is getting the middle element and then preceding and following sibling with the specified tag. But I feel like thats whacky at best.</p>

<p>Thx alot.</p>

<p>I'm not sure what code you are using for your approach but I would do something like this.</p>

<pre><code>headings = driver.find_elements_by_css_selector("parent &gt; h1"))
for i in range(len(headings)):
    heading = driver.find_element_by_css_selector("parent &gt; h1:nth-of-type(" + i + ")"))
    identifier = driver.find_element_by_css_selector("parent &gt; div.identifier:nth-of-type(" + i + ")"))
    subheading = driver.find_element_by_css_selector("parent &gt; h3:nth-of-type(" + i + ")"))
    // do something with each element here
</code></pre>

<p>Now you can reference each of the elements.</p>

<p>NOTE: This assumes that each of the elements always exists. If you are ever missing an <code>h3</code>, etc. this code will mismatch the groups.</p>

python html selenium xpath