Your problem doesn't likely involve normalize-space()
but rather one of two common text/string matching areas of confusion:
Text node vs string value
text()
matches text nodes.
//td[contains(text(), 'Some')]
will match this
<td>Some text</td>
but not
<td><b>Some text</b></td>
To match the latter too, use //td[contains(., 'Some')]
instead. This will check that the string value of td
contains the string "Some".
For more details, see XPath text() = is different than XPath . =
String contains vs string equals
Note also that contains()
tests for substring containment. If you want string equality, use the =
operator against string:
//td[. = 'Some']
Will match
<td><b>Some</b></td>
but not
<td><b>Some text</b></td>
Be aware of the difference.