Reputation: 11
Following is the html of the element that I am trying to construct the xpath for:
<div class="b-list-item" data-index="7" data-id="8">
Jong
</div>
I tried the following xpaths none of them worked:
//div[text()='Jong']
//div[.='Jong']
//div[@class='b-list-item' and text()='Jong']
I need to use the text to construct the xpath, can someone help in achieving it.
Upvotes: 0
Views: 645
Reputation: 1882
The problem might be that the text node containing Jong
string has leading and trailing new line characters 

.
Use the normalize-space()
function like this
//div[normalize-space()='Jong']
Upvotes: 1
Reputation: 163
I checked creating a dummy page with your given html elements and the below mentioned xpath has worked fine for me. Can you please try it?
xpath=//div[@class='b-list-item' and contains(text(),'Jong')]
Upvotes: 0