Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get element value from HTML response using Postman

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

"__RequestVerificationToken" is not a valid selector since it is a name attribute you’re looking for.

Instead, use the valid CSS selector like this:

const $ = cheerio.load(pm.response.text()).;
console.log($("input[name='__RequestVerificationToken']").attr('value'));
console.log($("input[name='__RequestVerificationToken']").text());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading