0

I have following rendered html

<div class="footer text-center">
  <p>By signing up, you agree to abc's <b>Terms of Service</b>, <b>Cookie Policy</b>, <b>Privacy Policy and Content Policies.</b></p>
</div>

I am trying following to validate text is appearing as expected. But getAttribute('value') returns Null and hence test failing.

element(by.tagName('p')).getAttribute('value').then(function (text) {
    expect(text).toBe("By signing up, you agree to abc's Terms of Service, Cookie Policy, Privacy Policy and Content Policies.");
}); 
simbada
  • 940
  • 4
  • 24
  • 43
  • you want [getText](http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getText). I would suggest you become familiar with the protractor API, plenty to learn on there. – Gunderson Nov 14 '17 at 17:22

3 Answers3

0

You should use the innerHtml property. Check this:

https://www.w3schools.com/jsref/prop_html_innerhtml.asp

konalexiou
  • 31
  • 3
0

You can use getText. It will return you all text from inner tags as well.

Yash Jagdale
  • 1,446
  • 14
  • 17
0

As you try to getText() as nicely formatted string, you should indeed use getText() as described in Protractor API. It will remove the <b>-tags and will also i.e. remove double-spaces.

Further because getText() returns a promise and because expect() will then resolve the promise, there is no need to use then() in your case.

Overall here is how your code should look like:

expect(element(by.tagName('p')).getText()).toBe("By signing up, you agree to abc's Terms of Service, Cookie Policy, Privacy Policy and Content Policies.");

Now some more valuable infos:

Ernst Zwingli
  • 1,402
  • 1
  • 8
  • 24