Using Xpath when you have new line text

Here is an example where there are new lines and have to validate if the exact text is displayed in the correct order using xpath.

User-agent: *
Disallow: /clickthrough.html
Disallow: /details.html
Disallow: /post-sendtofriend.html

Use normalize-space(), which will throw away the leading and trailing whitespace characters (and condense repeating spaces in the middle of the text into a single space), so that you can compare the normalized text() and use to filter in a predicate.
Here is the xpath code to validate the above text

selenium.getText("//test[normalize-space()]").Equals("pass the string here");

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>