Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protractor getText returns empty string for non-empty element

I have issues getting the text from an element in protractor. For other elements of the page it works as expected, just not for this one :/

<p class="error theme-info-i ng-binding ng-scope" ng-if="firstFormError && form.$invalid" ng-click="goToErrorField(firstFormError)">
  <span class="emphasize ng-binding">User ID</span> (The user ID is required.)
</p>

I can locate both elements without problems using by.className, and getInnerHtml/getOuterHtml works as expected. However getText returns an empty string for both.

like image 813
FrankyBoy Avatar asked Sep 15 '14 10:09

FrankyBoy


2 Answers

Found the reason ... its a two-step registration where the first step has the same notification area and just gets hidden. For reasons beyond my comprehension the devs update both notification areas (not just the one on the current page), so inner/outerHtml just seemingly returned the "correct content" and because the first area was hidden, getText returned empty as by spec.

I think I'm gonna file some internal bug report now wtf we are doing with those notifications ;)

like image 196
FrankyBoy Avatar answered Oct 16 '22 09:10

FrankyBoy


You can try

var firstName = element(by.model('firstName'))
expect(firstName.getAttribute('value'))

This gives you the value of the input box.

like image 22
Megha Avatar answered Oct 16 '22 08:10

Megha