3
votes

For some reason my assert in protractor fails, what i'm trying to do is get the innerHTML (text) from an element:

var stuff = $('css').html();

expect(stuff).toBe("Inner HTML Text here");

I verified that the $().html() yields the text i desire on the console, what is wrong with my expect statement?

TypeError: Object [object Object] has no method 'html'

2

2 Answers

4
votes

Use getInnerHtml()

expect($('.your-css').getInnerHtml()).toBe('your inner html');

http://angular.github.io/protractor/#/api?view=webdriver.WebElement.prototype.getInnerHtml

2
votes

The error message indicates that whatever object "$" returns, it doesn't have an "html" method.

If you expect "$" to be a reference to jQuery then try using "jQuery" explicitly e.g.

var stuff = jQuery('css').html();

Also, I'm not sure if the selector in the above statement is your actual selector, if so, it's looking for a "css" element which doesn't seem right. You might want to look at that.