1

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

Below is sample HTML:

<div class="class1">
    <a>
        <span>fourth<br>team</span>
    </a>
</div>

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

1 Answer 1

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']
0

Your Answer

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

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