Get element value from HTML response

Somewhere in the HTML response there is an element:

<input name="__RequestVerificationToken" type="hidden" value="I_NEED_THIS" />

How can I get itโ€™s value using Postman?

This is my code but Iโ€™m not happy with what it returns

const $ = cheerio.load(pm.response.text());
console.log($("title").text()); // get title to check if it works
console.log($("__RequestVerificationToken").attr('value')); //returns undefined
console.log($("__RequestVerificationToken").text()); //returns null

Hello @koshmariel,

Try using the below code.

console.log($('[name=__RequestVerificationToken]').val());

Cheers :smiley:

1 Like