Xpath exact match

351 views
Skip to first unread message

Patrik911

unread,
Oct 19, 2016, 3:27:07 PM10/19/16
to Selenium Users

Hello,

I try do select an element via xpath but do not find the solution.

//table[@id='tblCoverageGroupsForPlan']/tbody/tr/td[contains(.,'Ambulatory')]

My XPATH returns 2 element because there is a TD which contains "Ambulatory" and another one contains "Ambulatory Transport"

How can I select only the first one?

I also tried //table[@id='tblCoverageGroupsForPlan']/tbody/tr[1]/td[normalize-space(text())='Ambulatory']  but this does not give me a result.   I think the reason is that the text contains a second text the one between the span tags: "0/11"  but I am not sure.

This also return nothing?

//table[@id='tblCoverageGroupsForPlan']/tbody/tr[1]/td[normalize-space(text())='Ambulatory 0/11']

All suggestions are welcome. 

Thanks.








Auto Generated Inline Image 1

พอ สุวพรหม

unread,
Oct 20, 2016, 12:11:29 AM10/20/16
to Selenium Users
//table[@id='tblCoverageGroupsForPlan']/tbody/tr/td[contains(.,'Ambulatory')][1]   ?

Patrik911

unread,
Oct 20, 2016, 10:04:35 AM10/20/16
to Selenium Users
Your suggestion still gives me two matches because there are 2 td that contain Ambulatory   -->1) Ambulatory  and 2)Ambulatory Transport

The goal is to match the first one only?

Op donderdag 20 oktober 2016 06:11:29 UTC+2 schreef พอ สุวพรหม:

Praveen Kumar

unread,
Oct 20, 2016, 12:21:43 PM10/20/16
to Selenium Users
try using exact match in xpath instead of contains //table[@id='tblCoverageGroupsForPlan']/tbody/tr/td[text()='Ambulatory']

Patrik911

unread,
Oct 21, 2016, 3:49:46 AM10/21/16
to Selenium Users
Well for some reason this does not find the node.

If i am not mistaken this is because text also returns the text of the children in this case of the span element and maybe also due to the spaces and linefeeds in the html?






Op donderdag 20 oktober 2016 18:21:43 UTC+2 schreef Praveen Kumar:
Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages