Reputation: 21
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.
Upvotes: 1
Views: 103
Reputation: 168157
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:
Use Tidy
box. It may not be necessary but if your server response is not XML/XHTML compliant you'll get nothingvalue
- it will be the name of the variable holding extracted dataXPath Expression: //select[@class='card_account']/option[@selected='selected']/@value
- it will take
and store it to "value" variable. You will be able to refer to it as ${value}
where required.
See following material for further reference:
Upvotes: 1
Reputation: 627341
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.
Upvotes: 0