How to search element by substring text?

i have this text " Mon cadencier " with many space any where.
I just want to find the element wiht just the substring “cadencier”.
How can I do it?
Thanks in advance

1 Like

Please provide the full source of the HTML More preferably please share the URL of the target web page if it is publicly accessible. Without the subject HTML provided, nobody would be able to work on it.

This is the link of the web site

In the page, I found only 1 place where the text “Mon cadencier” is visible.

I looked at the element using the Chrome DevTools.

Ah, I found the text "Mon cadencier " has a trailing whitespace character 0x20. This one character is annoying the original poster, I suppose.

I suppose that you have a Test Object with a locator XPath expression like:

//a[text()='Mon cadencier']

This expression is sensitve to the trailing whitespace, so that it would fail to select the <a> element you want.

You can change the XPath as:

//a[contains(text(), 'cadencier')]

The XPath built-in function contains() will help you.

An alternative expression:

//a[normalize-space(text())='Mon cadencier']

The normalize-space() function of XPath will trim the padding white spaces.

Please be advised that the Spy & Recorder tools built-in Katalon Studio is not capable to solve this type of problems caused by padding whitespaces automagically out of box. You should learn the XPath expression and/or CSS Selector by reading some good tutorials and books.

See, for example, XPath in Selenium: How to Find & Write? (Text, Contains, AND) for more information about XPath.

With the knowledge about the backing technologies, you would be able to use the tools better.