1

Could someone help me in getting the value "1237857346" from the following using regex or any other way I could get the value "1237857346" in from HTML in JMeter.

<select class="card_account" name="existing__account">
  <option value="" disabled="disabled">Card Number</option>
  <option value="1237857346" selected="selected">************4567</option>
</select>

Little bit of background. I am using JMeter and trying to extra the value "1237857346" to pass it in the next request.

SET
  • 11
  • 2

2 Answers2

1

It is not very good idea to parse HTML using Regular Expressions as it evidenced by the famous Stack Overflow answer

I would suggest switching to XPath Extractor instead. Add the XPath Extractor as a child of HTTP Request sampler which returns that select and configure it as follows:

  • XML Parsing Options: tick Use Tidy box. It may not be necessary but if your server response is not XML/XHTML compliant you'll get nothing
  • Reference Name: anything meaningful, i.e. value - it will be the name of the variable holding extracted data
  • XPath Expression: //select[@class='card_account']/option[@selected='selected']/@value - it will take

    • select having class = card_account
    • option with selected = "selected"
    • value attribute of the above option

and store it to "value" variable. You will be able to refer to it as ${value} where required.

See following material for further reference:

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you. Yeah I know about XPATH as I work alot on then day to day. Your suggestion is working like a champ... Awesome :) – SET May 13 '15 at 01:27
0

You can use the following regex:

<option[^<]*>Card Number</option>\s*<option[^<]*?value="(\d+)"

The value will be in group 1 ($1$), which is exactly what you need.

See demo

In case the are always 12 asterisks (that can be matched with \*{12}) in the <option> node value, you'd can use:

<option[^<]*value="(\d+)"[^<]*>\*{12}\d+</option>

See another demo.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563