Skip to content

CSS Selector Extractor

Configure the JMeter CSS Selector Extractor post-processors: properties, defaults, and practical usage notes for building reliable load tests.

Difficulty
intermediate
Guide type
reference
Estimated read time
4 min read
Last verified version
Verified JMeter 5.6

Part of the Post-Processors category — formerly called CSS/JQuery Extractor. Also documented in context in the full Component Reference.

CSS Selector Extractor

Allows the user to extract values from a server HTML response using a CSS Selector syntax. As a post-processor, this element will execute after each Sample request in its scope, applying the CSS/JQuery expression, extracting the requested nodes, extracting the node as text or attribute value and store the result into the given variable name.

NameRequiredDescription
NameNoDescriptive name for this element that is shown in the tree.
Apply to:YesThis is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller. - Main sample only - only applies to the main sample - Sub-samples only - only applies to the sub-samples - Main sample and sub-samples - applies to both. - JMeter Variable Name to use - extraction is to be applied to the contents of the named variable Matching is applied to all qualifying samples in turn. For example if there is a main sample and 3 sub-samples, each of which contains a single match for the regex, (i.e. 4 matches in total). For match number = 3, Sub-samples only, the extractor will match the 3rd sub-sample. For match number = 3, Main sample and sub-samples, the extractor will match the 2nd sub-sample (1st match is main sample). For match number = 0 or negative, all qualifying samples will be processed. For match number > 0, matching will stop as soon as enough matches have been found.
CSS Selector ImplementationFalse2 Implementations for CSS/JQuery based syntax are supported: - JSoup - Jodd-Lagarto (CSSelly) If selector is set to empty, default implementation(JSoup) will be used.
Name of created variableYesThe name of the JMeter variable in which to store the result.
CSS/JQuery expressionYesThe CSS/JQuery selector used to select nodes from the response data. Selector, selectors combination and pseudo-selectors are supported, examples: - E[foo] - an E element with a “foo” attribute - ancestor child - child elements that descend from ancestor, e.g. .body p finds p elements anywhere under a block with class “body” - :lt(n) - find elements whose sibling index (i.e. its position in the DOM tree relative to its parent) is less than n; e.g. td:lt(3) - :contains(text) - find elements that contain the given text. The search is case-insensitive; e.g. p:contains(jsoup) - … For more details on syntax, see: - JSoup - Jodd-Lagarto (CSSelly)
AttributefalseName of attribute (as per HTML syntax) to extract from nodes that matched the selector. If empty, then the combined text of this element and all its children will be returned. This is the equivalent Element#attr(name) function for JSoup if an attribute is set. CSS Extractor with attribute value set CSS Extractor with attribute value set If empty this is the equivalent of Element#text() function for JSoup if not value is set for attribute. CSS Extractor with no attribute set CSS Extractor with no attribute set
Match No. (0 for Random)YesIndicates which match to use. The CSS/JQuery selector may match multiple times. - Use a value of zero to indicate JMeter should choose a match at random. - A positive number N means to select the nth match. - Negative numbers are used in conjunction with the ForEach Controller - see below.
Default ValueNo, but recommendedIf the expression does not match, then the reference variable will be set to the default value. This is particularly useful for debugging tests. If no default is provided, then it is difficult to tell whether the expression did not match, or the CSS/JQuery element was not processed or maybe the wrong variable is being used. However, if you have several test elements that set the same variable, you may wish to leave the variable unchanged if the expression does not match. In this case, remove the default value once debugging is complete.
Use empty default valueNoIf the checkbox is checked and Default Value is empty, then JMeter will set the variable to empty string instead of not setting it. Thus when you will for example use \${var} (if Reference Name is var) in your Test Plan, if the extracted value is not found then \${var} will be equal to empty string instead of containing \${var} which may be useful if extracted value is optional.

If the match number is set to a non-negative number, and a match occurs, the variables are set as follows:

  • refName - the value of the template

    If no match occurs, then the refName variable is set to the default (unless this is absent).

    If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:

  • refName_matchNr - the number of matches found; could be 0

  • refName_n, where n = 1, 2, 3, etc. - the strings as generated by the template

  • refName - always set to the default value

    Note that the refName variable is always set to the default value in this case.

On this page