How to verify the text in a paragraph element in Nightwatch?
Asked 07 September, 2021
Viewed 868 times
  • 60
Votes

I have a text on a page and i have to verify that the text is present. The html for the element is <p class="subfooter__text" data-v-79ab1348=""> The Tesla is part of the <a href="//www.xyz.com/" target="_blank" rel="noopener nofollow">Automobile</a> publishing family.</p>

The text need to be verified is "The Tesla is part of the Automobile publishing family". The issue is, the assertion fails when asserted for full text, but it does pass when asserted for "Automobile" or "publishing family" or "Automobile publishing family". The assertion never passes for the text before the href tag.

Here is the code part browser.assert.containsText('p.subfooter__text', 'The Tesla is part of the Automobile publishing family'); I made sure that all spaces are taken care. Any help is greatly appreciated.

1 Answer