Reputation: 305
I have the following HTML DOM. My goal is to get the "Error" text.
<div class = "row">
<div class ="col-sm-4">
<input id = "firstName" type = "text"> John
<div class = "mh-15">
<div class = "text-danger">Error</div>
</div>
</div>
</div>
As class = "text-danger" is repeated numerous times, my goal is to get to the "Error" text by starting from id = "firstName" and going down the way by using something like an xpath ancestor. How should i do that? Thanks!
Upvotes: 2
Views: 89
Reputation: 19164
ancestor
is for selecting parent element, the class="text-danger"
is after the element of id="firstName"
you have to select it with following
or following-sibling
//input[@id="firstName"]/following-sibling::div/div
# or
//input[@id="firstName"]/following::div/div
Upvotes: 2
Reputation: 29382
Xpath :
//input[@id='firstName']/following-sibling::div[2]
Note that <div class = "mh-15">
should be sibling of input box.
Upvotes: 2