Reputation: 13
I am trying to select an element that contains a piece of text but I do not want to select the elements that contain the text plus additional text. I would normally use text()='abc def'
, but this particular element contains spaces before and after.
Here is an example snippet:
<div>
<div>
abc def
</div>
<div>
abc def ghi
</div>
<div>
abc def ghi jkl
</div>
</div>
I want to select the first div but //div[text()='abc def']
does not work because of the leading spaces and //div[contains(text(),'abc def']
also does not work because it will select all of the divs.
I have looked into normalize-space
and starts-with
, but I could not get it to quite work.
Upvotes: 1
Views: 328