Skip to content Skip to sidebar Skip to footer

Xpath To Get Data Starts With Specific Character Or String

I need to extract certain text elements from the following code.

Solution 1:

" Is there any xpath like "//div[@class='inhalt-links']/text[starts with "Tel.:"]" to select the Tel.: element?"

Sure, try this way :

//div[@class='inhalt-links']/text()[starts-with(normalize-space(), 'Tel.:')]

The XPath returns text node -rather than element- that starts with, after removing leading and trailing whitespaces*, the keyword Tel.:.


*) For reference of what normalize-space() is doing more precisely :

The normalize-space function strips leading and trailing white-space from a string, replaces sequences of whitespace characters by a single space, and returns the resulting string. [Mozilla Developer Network]

Post a Comment for "Xpath To Get Data Starts With Specific Character Or String"