Protractor getText from hidden element.

Protractor getText from hidden element.

Ran across a point that I wanted to get the value of a hidden element while running my Protractor tests. getText() function was not helpful at all. In order for it to return text it has to be visible. There is an option called getAttribute('textContent'). This will allow you to always return the text.

Sample HTML

  <span style="display: none" name="hiddenSpan">Hidden Text</span>

Sample Protractor JS

  $('[name="hiddenSpan"]').getText();
  // returns ""
  $('[name="hiddenSpan"]').getAttribute('textContent');
  // returns "Hidden Text"