normalize-space(.) versus text(.)
Reza Roozbehani
Software Testing Automation Engineer . Java / Rest Assured / Selenium / Jmeter / TestNG / JavaScript / Api Testing / Oracle / Git / Eclipse / IntelliJ / Maven
if you want to locate a paragraph of text which contains some styling:
<p>A paragraph with <b>this text in bold</b>.</p>
?
This will not be matched by the following XPath:
//*[contains(text(), 'A paragraph with this text in bold')]
?
Whereas this XPath will match:
//*[contains(normalize-space(.), 'A paragraph with this text in bold')]
?
text(.) matches only against the text of the element, whereas normalize-space(.)
returns the text of the element, and of all the elements it contains.