I want to get the text inside the element that comes after a certain text ie. 'Projected earning growth'. I want to get the value 18.10% . The pattern I want to follow is lookup for a certain text as above, and then get the text following the immediate h2 element.
Is it possible to have one xpath expression that will do both the steps together?
How do I match for a text and get to the next immediate h1 element via xpath?
<div>
<div class="p small mb-8 box-label text-left text-blue-500">
<div class="tt-container">
<button aria-label="open tooltip" class="button link" type="button" role="tooltip" aria-expanded="false">
Projected earning growth
</button>
</div>
</div>
<h2 class="mb-8 text-left">18.10%</h2>
</div>
If I understood you correctly, you want to go from Projected earning growth
to 18.10%
which is in h2 tag. Not sure why you've mentioned h1 tag though.
//button[contains(text(),'Projected earning growth')]/../../following-sibling::h2
should get the job done,
Note that /..
to go to go level up in HTMLDOM.
This is straight up solution to the problem that you are having.
I would also suggest you to have a look on xpath
parent and ancestor
.