I would rather recommend not using regular expressions for getting data from HTML as href
attribute may be located in differently, at new line, etc. See the epic comment on SO for detailed explanation.
JMeter provides 2 test elements which can be used to extract href
attribute from HTML page links:
XPath Example
- Add XPath Extractor as a child of the request (just like Regular Expression Extractor)
- Configure it as follows:
- If your response is not XHTML compliant - check
Use Tidy
box
- Reference name - anything meaningful, i.e.
href
- XPath query -
//a/@href
- You can refer to extracted link URL as
${href}
anywhere in current thread group.
- In case of multiple matches URLs can be accessed as
${href_1
} ${href_2}
etc.
For more information on the XPath Extractor see Using the XPath Extractor in JMeter guide
CSS/JQuery Example
- Add CSS/JQuery Extractor as a child of the request
- Configure it as follows:
- Reference name - any variable name, i.e.
href
- CSS/JQuery expression -
a
- Attribute -
href
- Match no:
- default is
blank
- will return the first link
any number > 0
- will return match number
0
- will return random link URL
-1
- will return all link URLs and store them as ${href_1
} ${href_2}
etc.
For CSS/JQuery expressions building information refer to JSOUP selector syntax guide