I've searched for a while trying to find a way in Postman to extract a HTML description list value from the response body where the description list contains multiple values.
Example of response body:
<dl>
<dd>Fruit</dd>
<dt>Apple</dt>
<dd>Vegetable</dd>
<dt>Carrot</dt>
</dl>
How do I just get just the Vegetable value? I've tried using the following
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').text())
This then returns both values
"Vegetable" "AppleCarrot"
The Fruit & Vegetable values will change once the request is rerun, this means I'm unable to go just based off their names.
I'm probably over thinking this, thanks in advance.
EricG posted the following above.
JQuery allows you to filter based off order using the following:
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').first().text())
Alternatively to the above if you need to go further down the list you can use:
const $ = cheerio.load(pm.response.text())
console.log('Vegetable', $('dt').eq(0).text())
Changing the value in .eq(#) starting from 0 will then following the items down the list.