I have below HTML code with me. I need to console log or print only the desc
class text - \"Print this\" and not the spell
class text in protractor or
I used Michael's solution and embedded into my test spec without calling the function. It would still be better to use it as a separate function if the need to use is recurring. However if you want an inline solution, Here's how to do it -
it("Get First part of text", function(){
browser.executeScript(function () {
var el = arguments[0], text = '';
for (var i = 0, l = el.childNodes.length; i < l; i++)
if (el.childNodes[i].nodeType === Element.TEXT_NODE)
text += el.childNodes[i].nodeValue;
return text.trim();
},$('.desc').getWebElement()).then(function(text){
//use expect statements with "text" here as needed
});
});
Hope it helps.