5

I have a problem. I am using Regular Expression Extractor in Jmeter. I have two regex.

I can get the value from this.

Reference Name: as_fid_addtobasket

Regular Expression: <input type="hidden" name="as_fid" value="(.+?)" />

Template: $1$

But i can't get the value from this one.

> Reference Name: DynamicTempOrderProductGuid 
> 
> Regular Expression: <input data-val="true" data-val-required="The
> TempOrderProductGuid field is required."
> id="OrderProducts_1__TempOrderProductGuid"
> name="OrderProducts[1].TempOrderProductGuid" type="hidden"
> value="(.+?)" />
> 
> Template: $1$
> >

Here is my result. The second one doesn't get the value. Where is the thing i missed?

POST data: OrderProducts.index=1&OrderProducts%5B1%5D.TempOrderProductGuid=%24%7BDynamicTempOrderProductGuid%7D&OrderProducts%5B1%5D.Count=1&OrderProducts%5B1%5D.ReceiverModel.OrderReceiver.NameRec=Test+ama%C3%A7l%C4%B1d%C4%B1r.+L%C3%BCtfen+dikkate+almay%C4%B1n%C4%B1z&OrderProducts%5B1%5D.ReceiverModel.OrderReceiver.PhoneRec=05352233285&OrderProducts%5B1%5D.ReceiverModel.OrderReceiver.OSSendingReason=&OrderProducts%5B1%5D.ReceiverModel.OrderReceiver.OSReceiverAddressType=&OrderProducts%5B1%5D.ReceiverModel.OrderReceiver.CompanyNameRec=&OrderProducts%5B1%5D.ReceiverModel.OrderReceiver.AddressLineRec=Test+ama%C3%A7l%C4%B1d%C4%B1r.+L%C3%BCtfen+dikkate+almay%C4%B1n%C4%B1z&OrderProducts%5B1%5D.ProductCode=se213&OrderProducts%5B1%5D.TempOrderProductGuid=%24%7Btokentoken%7D&totalProducts=1&as_fid=efWZ0i4RGLmC2nBWk%2FA1

cell-in
  • 709
  • 2
  • 11
  • 27
  • You really shouldn't try to parse HTML with regex: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#answer-1732454 . Consider a parser solution instead, especially if you have weird bugs :) – Robin Jan 23 '14 at 17:00
  • First of all, you have a `"` in the middle of your `data-val-required` attribute. This may or may not be adversely related to your issue. – tenub Jan 23 '14 at 17:00

3 Answers3

2

I would recommend using XPath Extractor instead as regular expressions are pretty dependent on layout, attributes order, spaces, etc. and can be a real headache to develop and test for non-experienced used. Especially multi-line ones.

XPath expression for extracting value from as_fid input will look like:

//input[@id='OrderProducts_1__TempOrderProductGuid']/@value

Some clues:

  1. If you're using JMeter 2.11 you'll be able to test your XPath expressions right in View Results Tree Listener
  2. You may need to check "Use Tidy" box in XPath Extractor if your HTML isn't XHTML compliant
  3. Check XPath Tutorial for language reference.
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you Dmitri! I got the value of my second xhmtl script using xpath extractor. This is my solution. //input[@id='OrderProducts_1__TempOrderProductGuid' and @data-val='true']/@value – cell-in Jan 30 '14 at 09:04
0

Try this simpler regex for your second case:

<input.+?value="(.+?)"\s*/>

Demo

http://regex101.com/r/nI8nZ9

Stephan
  • 41,764
  • 65
  • 238
  • 329
0

You can update the regex as the followings to get the valid DynamicTempOrderProductGuid

Reference Name: DynamicTempOrderProductGuid 
Regular Expression: name="(.+)"\stype="hidden"value="(.+)"
Template: $2$
Juan Mellado
  • 14,973
  • 5
  • 47
  • 54