I'm having a trouble selecting preceding siblings. Here's the html:
<div>
<h2>Apple</h2>
<div class="row">A</div>
<h2>Banana</h2>
<div class="row">B</div>
<h2>Strawberry</h2>
<div class="row">C</div>
</div>
My XPath: preceding-sibling::h2.
What I want to do: Select every closest previous h2 element for every div.row .
For example, div.row A gives me Apple h2, div.row B gives me Banana h2 and div.row C gives me Strawberry h2.
The problem is my XPath was wrong, it only selected Apple h2 for every div.row. How can I fix this?