How to extract a value attribute from an input tag where the body is a web page?

I’m running a GET call to return a web page as body
I want to extract the value attribute of a named ‘input’ tag from the XML body.
Any suggestions on how to do this?
TIA

Hey @davout_uk. Can you help me understand the use case better?
From what I know so far, you are trying to parse an XML response from a GET request to get a particular value. Here’s how you can do that.

The pm.reponse API does not have a .xml() method to parse XML responses directly, you can read more about the API here. To do so, you’ll need to use one of the built-in library modules, called xml2js. Your test script would look something like.

var parseString = require('xml2js').parseString;

parseString(pm.response.text(), function (err, result) {
    pm.globals.set("xml_parsed_response", JSON.stringify(result));
});

Now that you have the parsed XML response stored as a global variable, you can access it in the subsequent request using pm.globals.get("xml_parsed_response"); and access the required key using the dot notation.

Remember that parseString is an asynchronous function and you’ll have to set the result to a global/environment variable to access it in subsequent requests.

Feel free to reach out in case this wasn’t your exact query or if you need additional help.

1 Like

It sounds like you are interested in parsing HTML and not XML.

It that is the case, I would suggest looking into the cheerio library.

I have done a tutorial on how to use cheerio in this video: https://youtu.be/B4ilccLUQVs

Otherwise please clarify the questions, as @deepak.pathania suggested.

Thanks vdespa, you helped me solving my problem.
regards