5

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.

3 Answers 3

4

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 ;)

Sign up to request clarification or add additional context in comments.

Comments

3

You can try

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

This gives you the value of the input box.

1 Comment

.getAttribute('value') may not work. You can also try .getAttribute('textContent') or .getAttribute('innerText')
2

Had the same problem.

expect(element(By.css('span.emphasize.ng-binding')).getAttribute('textContent'))...

Seems to work just fine for me (this of course if you have only one span with those classes or is the first one. else you need to be more specific. But anyway if you still need to solve the problem try with .getAttribute('textContent') )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.