I want to read the data which is inside the second div
:
<div class="my-3">
<div class="d-flex justify-content-between">Monthly:</div>
<div>0 / 30,000</div>
</div>
In the above markup, I want to read the div
which contains the string: 0 / 30,000
I was able to navigate to the first div
which contains the string "Monthly:"
with this XPath:
//*[normalize-space()='Monthly:']
How can I select the second div
below after that?
2
Answers
Use this:
Limitations of currently accepted answer
The XPath in the currently accepted answer,
works for OP’s exact case where there is a single
div
following the targeted label,but can produce different results if there are multiple
div
sibling elements following the target.For example, consider this markup:
In this case, it won’t just be
<div>0 / 30,000</div>
that’s selected, butMore robust XPath for labeled data
To select only the immediately following
div
element, use this XPath instead:To select only the immediately following element of any name: