# Cannot get text from element inside DOM in Cheeriojs

**URL:** <https://community.postman.com/t/cannot-get-text-from-element-inside-dom-in-cheeriojs/20094>\
**Category:** Help Hub\
**Created:** [February 5, 2021, 5:05pm UTC](https://community.postman.com/t/cannot-get-text-from-element-inside-dom-in-cheeriojs/20094 "2021-02-05T17:05:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sstadnik](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sstadnik](https://community.postman.com/u/sstadnik)\
**Post date:** [February 5, 2021, 5:05pm UTC](https://community.postman.com/t/cannot-get-text-from-element-inside-dom-in-cheeriojs/20094/1 "2021-02-05T17:05:14Z")

</div>

I am using Postman to write UI tests, and need to get a text from the element inside the DOM.

What is the correct syntax to do so? ? The structure of the webpage is div-\>ul-\>li-\>class

The test passes every time, even with the wrong text. I would appreciate any examples.

> Blockquote  
> `var cheerio = require('cheerio'); const $ = cheerio.load('<ul class="cards-wrapper">...</ul>'); $.html(); pm.test('Test name', function () { $('.cards-wrapper').text("12345"); });`

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [February 6, 2021, 2:44am UTC](https://community.postman.com/t/cannot-get-text-from-element-inside-dom-in-cheeriojs/20094/2 "2021-02-06T02:44:10Z")

</div>

@sstadnik Welcome to the Community 💐

So did you tried to print and see the

```auto
 console.log($.html());

```

Also in your Test I see that the value to validate against should be given in different format.

```auto
var cheerio = require('cheerio'); 
const $ = cheerio.load('<ul class="cards-wrapper">...</ul>'); $.html(); 

pm.test('Test name', function () { $('.cards-wrapper').text().to.eql("12345"); });

});

```

I have an example using SOAP XML response.

Body is as

```auto
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>500</ubiNum>
    </NumberToWords>
  </soap:Body>
</soap:Envelope>

```

Under Tests I have written so

```auto
var cheerio = require('cheerio');
pm.test("Cheerio",() => {
    const $ = cheerio.load(responseBody,{
        ignoreWhitespace: true,
        xmlMode: true
    });

    //Render XML
  console.log("Entering logic");
    console.log($.xml());

pm.test("Using Cheerio ", function () 
{
pm.expect($('m\\:NumberToWordsResponse').attr('xmlns:m')).to.eql('http://www.dataaccess.com/webservicesserver/')
pm.expect($('m\\:NumberToWordsResult').text()).to.eql("five hundred ");
});

});

```

Please check if its useful to you. If these doesn’t answer your question, please post with few other details 🙂 We would love to help!!

---

<div class="post-metadata">

**Author:** ![sstadnik](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sstadnik](https://community.postman.com/u/sstadnik)\
**Post date:** [February 7, 2021, 4:48pm UTC](https://community.postman.com/t/cannot-get-text-from-element-inside-dom-in-cheeriojs/20094/3 "2021-02-07T16:48:23Z")

</div>

@bpricilla Thank you very much for your help.

console.log($.html()); did not produce any results

I think the problem might be in using shadow dom on that website.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [February 8, 2021, 3:29am UTC](https://community.postman.com/t/cannot-get-text-from-element-inside-dom-in-cheeriojs/20094/4 "2021-02-08T03:29:40Z")

</div>

@sstadnik, yes please try to parse the response.

Else you can provide the html response here 🙂

May be this [source](https://github.com/cheeriojs/cheerio/blob/main/Readme.md) about cheerio would help you in a way.
