-1

I have a question regarding xpath. I try to locate the element that is in a drop down for example Surveys when I try to search using contains it is working

//li[contains(text(),'Surveys')]

But when I tried to search exact it is failed

//li[text()='Surveys']

Can someone please advise?

enter image description here

Bastian
  • 1,089
  • 7
  • 25
  • 74

4 Answers4

2

The text Surveys have a lot of white-spaces around it. So alternatively to suppress the white-spaces you can use the following Locator Strategy:

//li[normalize-space()='Surveys']
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Use normalize-space to remove whitespace characters:

//li[normalize-space(.)='Surveys']
Sers
  • 12,047
  • 2
  • 12
  • 31
0

Your "exact match" is missing the "new line" character, "\n". Try:

//li[text()='Surveys\n']
Jortega
  • 3,616
  • 1
  • 18
  • 21
-1

I have tried it before, but you can try a newer way, I am still using it and it is working fine

right click --> copy XPath --> fix " "

D2K
  • 1
  • 4