user22548444
user22548444

Reputation:

XPath find element if children element contains text

Say I have the following elements

<div class="someDiv">
   <p class="someP">1</p>
   <span class="someP">2</span>
   <h1 class="someP">3</h1>
</div>
<div class="someDiv">
   <p class="someP">4</p>
   <span class="someP">5</span>
   <h1 class="someP">6</h1>
</div>

I want to find the div that has any child elements that contain text '1' or '3' (which means the first div). I can search on any text (which the elements are not known so it needs to be dynamic - I used span, h1 and p tags as an example but they could be other tags).

tried using ancestor and sibling but could not find a way to find the parent div element

Upvotes: 0

Views: 42

Answers (1)

//div[//*[contains(text(), "1") or contains(text(), "3")]]

Upvotes: 0

Related Questions