I want to get the text (SampleList23.csv) that is present between 2 spans.


<div class="ng-scope" ng-switch-when="false">
    <div class="engage-tag ng-binding">
        <span class="icon-doc-generic-b"/>
        <span class="icon-close close" ng-click="unsetImportFile()"/>

Code I have tried:

   1.  expect(element(by.xpath(".//*[@class='engage-tag ng binding']/*")).getAttribute("value")).toContain("SampleList23.csv");
   2.  expect(element(by.xpath("//*[@class='engage-tag ng-binding']/child::node()", 'SampleList23.csv); 
   3.  expect(element(by.xpath("//*[@class='engage-tag ng-binding']/*", 'SampleList23.csv); 

All above failed to get text.

  • It would be good to know the output in case of all the three options that you've tried. Oct 9, 2017 at 15:44
  • It looks like you should be able to just get the text() in the div . . .
    – ernie
    Oct 9, 2017 at 17:17

1 Answer 1


Since your span elements don't have a text, you can basically "ignore" them. In other words, get the parent div element and get the text via getText():

  • Will getText() fetch you the text here? Doesn't it require resolving a promise? As per link it does. Oct 10, 2017 at 4:31
  • @demouser123 in Protractor, expect() is internally patched to implicitly resolve promises before executing the assertions. This is quite handy. Thanks.
    – alecxe
    Oct 10, 2017 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.