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?

alecxe
  • 11,425
  • 10
  • 49
  • 107
Sandesh Sawant
  • 97
  • 2
  • 6
  • 15

1 Answers1

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']
alecxe
  • 11,425
  • 10
  • 49
  • 107