3

I'm trying to extract a value from a response to a GET HTTP and storing this value in an environment variable using POSTMAN, then i would use this value for the next HTTP request. This is is an extract of the body response:

 <p style="display:none;"><input type="hidden" name="sessionid" id="sessionid" value="e8e63af56d146f42e80f6cd8602cd304708efa58d60e9a43f91cb12e8a2064f4"/><input type="hidden" name="submitbutton" id="submitbutton" value=""/></p>

I need to extract the "value" and then storing it inside an environment variable. how can i accomplish this using Test scripting in POSTMAN?

thanks

Update: After receiving help from this community and this link: https://community.getpostman.com/t/how-to-extract-a-value-attribute-from-an-input-tag-where-the-body-is-a-web-page/1535/2

I was able to do all the stuff, here my code:

var responseHTML = cheerio(pm.response.text());
var variabile = responseHTML.find('[name="sessionid"]').val();
console.log(variabile);
pm.globals.set("session", variabile);

now i can see the sessionid value saved inside the global variable.

Marco_81
  • 153
  • 1
  • 5
  • 20
  • Have you written any test script, if yes, please share that. – gauri Sep 05 '18 at 13:33
  • var jsonObject = xml2Json(responseBody); console.log(jsonObject); pm.environment.set("sessionid", jsonObject.?????); i don't know what to fill in place of ???? – Marco_81 Sep 05 '18 at 13:34
  • Do you think the HTML body response i provided is enough to retrieve the exact code? – Marco_81 Sep 05 '18 at 14:31
  • 2
    Would this help https://stackoverflow.com/questions/51919983/postman-how-to-extract-value-from-html-response-and-pass-it-on-to-next-request/51931624#51931624 – Danny Dainton Sep 06 '18 at 07:30
  • 1
    Great, cheerio is the response. Also this link helped a lot: https://community.getpostman.com/t/how-to-extract-a-value-attribute-from-an-input-tag-where-the-body-is-a-web-page/1535/2 – Marco_81 Sep 06 '18 at 10:15

0 Answers0