I need to get the span element by matching its entire text which has a line break.

Below is sample HTML:

<div class="class1">

I know we can use //span[contains(text(),'fourth')], but is there any way to match the entire text?

1 Answer 1


If you insist on using XPath, you could use normalize-space() function which would take care of spaces and newlines for you:

//a[normalize-space(span) = 'fourthteam']

Or, if you'd like to locate the span element instead:

//span[normalize-space(.) = 'fourthteam']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.