1

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

HTML:

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

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. – demouser123 Oct 9 '17 at 15:44
  • It looks like you should be able to just get the text() in the div . . . – ernie Oct 9 '17 at 17:17
2

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():

expect($(".engage-tag").getText()).toEqual("SampleList23.csv");
  • Will getText() fetch you the text here? Doesn't it require resolving a promise? As per link it does. – demouser123 Oct 10 '17 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 '17 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.