Harish
Harish

Reputation: 11

xpath is not able to identify the webelement

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

Answers (3)

Alejandro
Alejandro

Reputation: 1882

The problem might be that the text node containing Jong string has leading and trailing new line characters &#xA;.

Use the normalize-space() function like this

//div[normalize-space()='Jong']

Upvotes: 1

Jasvinder Singh Chugh
Jasvinder Singh Chugh

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

Jagadeesh
Jagadeesh

Reputation: 398

Use this xpath //div[@class='b-list-item'], it should work

Upvotes: 0

Related Questions