-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
  • 901
  • 4
  • 20
  • 52

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
  • 151,581
  • 34
  • 225
  • 281
0

Use normalize-space to remove whitespace characters:

//li[normalize-space(.)='Surveys']
Sers
  • 11,624
  • 2
  • 9
  • 29
0

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

//li[text()='Surveys\n']
Jortega
  • 3,151
  • 1
  • 16
  • 19
-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
  • 3