简体   繁体   中英

jmeter extract regular expression not get correct result

This is my html

<input name="__RequestVerificationToken" type="hidden" value="A9y6Ndf7Q2XP2Yz6zhaVChoIvpQGUrZRTvu9D_HnHnUcFBVInerxCjU4vpOXQYVhFwnzl-zAzkvtto7BLAVVr">

I want to extract value in jmeter Regular Expression Extractor. 在此处输入图片说明

This is my regx window but when i post it i will not get expected token it is something like this __RequestVerificationToken=%24%7Bauth_token%7D .

Try using $1$ as a Template, it should resolve your issue.

Looking into your request I can see that you're sending %24%7Bauth_token%7D which being decoded looks like ${auth_token} so you use case is not correct.

You need 2 requests:

  1. GET request to get the page and extract RequestVerificationToken and store it to auth_token variable.
  2. POST Request which will use auth_token variable.

See Using Regular Expressions in JMeter guide for more details.

By the way, you can use combination of Debug Sampler and View Results Tree listener to see if there are any matches. It should be more convenient wrt groups and variables.

In general, it isn't recommended to use Regular Expressions to parse HTML. I would suggest to use XPath Extractor instead. Relevant XPath expression will look like:

//input[@name='__RequestVerificationToken']/@value

Few things to notice:

  • If you page isn't XHTML compliant you'll need to check Use Tidy box in XPath Extractor
  • JMeter 2.11 provides nice XPath Tester right in View Results Tree Listener

We need to set the following Regular Expression Extractor values to extract the auth token values

Reference Name : Auth_Token
Regular Expression : <input\sname="__RequestVerificationToken"\stype="hidden"\svalue="(.+)">
Template : $1$
Match No : 1
Default values : NOT FOUND TOKENS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM