Question

Currently I'm doing a course on JMeter and I am stuck on something with which I would be grateful if you could point me in the right direction. Using the regular expression extractor I am trying to write a regular expression to extract the values from drop down lists for parameterisation reasons. However, using my expression seems to extract everything on the page which has "option value" in that page i.e i am unable to make the expression to be specific for a particular drop down? many thanks

I have tried:

OPTION VALUE="([A-Za-z]+)"

The following is the relevant HTML:

<SELECT NAME="fromPort">
    <OPTION VALUE="Acapulco">Acapulco
    <OPTION VALUE="Frankfurt">Frankfurt
    <OPTION VALUE="London">London
    <OPTION VALUE="New York">New York
    <OPTION VALUE="Paris">Paris
    <OPTION VALUE="Portland">Portland
    <OPTION VALUE="San Francisco">San Francisco
    <OPTION VALUE="Seattle">Seattle
    <OPTION VALUE="Sydney">Sydney
    <OPTION VALUE="Zurich">Zurich
</SELECT>     
Was it helpful?

Solution

This is a poor situation for using the Regex extractor because regular expressions are for matching specific strings.

You want to match based on the DOM so try the XPath extractor instead.

A rough example for your situation would be:

/html/body/select[@name="fromPort"]/option/text()

A tutorial here if you'd like some help: http://blazemeter.com/blog/using-xpath-extractor-jmeter-0

OTHER TIPS

Don't use Regular Expressions to extract HTML data. See RegEx match open tags except XHTML self-contained tags for details.

JMeter offers 2 Post Processors designed for dealing with HTML data.

XPath Extractor

Add XPath Extractor as a child of the request which is returning your port data configured as follows:

  • Reference name: anything meaningful, i.e. port. It'll be variable or variable prefix for matches results
  • XPath query: //select[@name='fromPort']/option/text()
  • Important: if your response is not XML/HTML compliant - check Use Tidy box, it enables XPath Extractor to parse invalid XML/XHTML responses.

The output will be like:

port=Acapulco
port_1=Acapulco
port_10=Zurich
port_2=Frankfurt
port_3=London
port_4=New York
port_5=Paris
port_6=Portland
port_7=San Francisco
port_8=Seattle
port_9=Sydney
port_matchNr=10

CSS/JQuery_Extractor

Another options is using CSS/JQuery extractor which allows using CSS and/or JQuery expressions to fetch interesting parts of the response.

For example, if you're looking for random port following configuration may be helpful:

  • Reference name: again, something meaningful, for instance port
  • CSS/JQuery expression: select[name=fromPort] > option
  • Attribute: value

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top