Hello. I’ve found related answers to this in my search, but this isn’t quite working. I’m trying to use Postman to 1) register test users in my Flask site, 2) test duplicate registration. The Flask app presents the csrf-token in a hidden field in the html. In order to test user registration, I think I need to create a Postman pre-request script to grab that csrf-token and set it in a variable which the registration test will use. Here’s what I have:
In this first screenshot you see the setup of the form-data being sent to register a user. Is this the correct way to set the csrf-token as a variable. Below in the screenshot I’m showing the html output generated by the GET pre-req script, noting the csrf-token in the hidden field.
In your pm.sendRequest you using an arg called html and then using that in the cheerio.load().
If you’re using pm.sendRequest and are looking to use the response from that call, I would try and use cheerio.load(response.text()) to see if that give you what you need to extract the token.
FWIW, the proof of concept I show in my original post, using node, worked wherein I loaded cheerio with the html and I was able to ‘find’ the token in the ‘contentSection’. I know that node and pm aren’t the same, but I’m puzzled.