Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Jmeter extracting __RequestVerificationToken and using it to log in

I am currently using Jmeter to automate this process however I am not able to automate the login process. I have used the following regular expression to extract the __RequestVerificationToken <input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/\-\_]+?)">

enter image description here

I then proceed to request the token when attempting to log in

When running the test however I am receiving Response code of 500. When investigating the request data the token is not being pulled correctly

enter image description here

like image 607
Jfegan91 Avatar asked Nov 15 '25 09:11

Jfegan91


1 Answers

Remember not to use regular expressions to parse HTML data. It is a real headache to develop and maintain regular expressions dealing with HTML code, moreover regular expressions are very sensitive to any markup change (line break, extra space, attributes order change, etc.) so I would recommend considering switching to CSS/JQuery Extractor instead. The relevant configuration will be as simple as:

  • Reference name: anything meaningful, tok will be fine
  • CSS/JQuery Expression: input[name=__RequestVerificationToken]
  • Attribute: value

This way you will have robust and reliable way of extracting the __RequestVerificationToken value.

Demo:

JMeter CSS Jquery Extractor

See How to Use the CSS/JQuery Extractor in JMeter article for more information.

like image 154
Dmitri T Avatar answered Nov 18 '25 19:11

Dmitri T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!