Dynamic HTML pages often hide request values inside forms, links, and data attributes. JMeter's CSS Selector Extractor reads an HTML response and saves a matched value in a variable for a later request.
An extractor attached to an HTTP Request runs after that request and reads the HTML returned by the server. The selector finds an element, while Attribute determines whether JMeter stores an attribute or the element's text. Values created only by browser JavaScript are absent from the server response and cannot be extracted this way.
The test plan needs an HTML-producing request followed by the request that uses its value in the same thread. A checkout form with a hidden csrf_token field makes reuse easy to check because the submission fails when its token is missing or wrong. One user, one loop, and a View Results Tree listener are enough to inspect that exchange.
Steps to extract an HTML value with a JMeter CSS Selector Extractor:
- Select the HTTP Request that returns the HTML containing the value.

- Add a CSS Selector Extractor from the request's right-click menu under Add → Post Processors.

- Enter csrf_token in Name of created variable.
The default Main sample only scope reads the request's main response. A blank CSS Selector Extractor Implementation uses JSoup.
- Enter input[name=csrf_token] in CSS Selector expression.
This selector matches the input named csrf_token in the response HTML. The field name must match the HTML returned by your application.
- Set Attribute to value.
The value attribute contains the hidden input's token. An empty Attribute returns element text instead, which does not read a hidden input's value.
- Set Match No. (0 for Random) to 1.
A value of 1 selects the first matching element; 0 selects a random match.
- Enter TOKEN_NOT_FOUND in Default Value.
The unchecked Use empty default value option and a recognizable default make a missing match visible during debugging.
- Select the later POST request that submits the form.

- Set the Value of its csrf_token parameter to ${csrf_token}.
The parameter's Name is the form field expected by the server. Its Value references the JMeter variable rather than a token copied from an earlier response.
- Save the test plan.
A checkout POST can place a real order. Do not run this test against a live checkout.
- Run the plan once with the Start toolbar button.
- Select View Results Tree.

- Select the submitted request in the results list.

- Open Response data for that result.

- Confirm that the form submission succeeds with the extracted value.
The checkout shown here returns Checkout complete after accepting the token, and HTTP 403 for a missing or invalid token. Your application's expected success response provides the corresponding check. A request containing TOKEN_NOT_FOUND indicates a missed selector match.
Related: How to add a Debug Sampler in JMeter