Regular Expression

  • Writing regular expression for below code

    <select name="fromPort" class="form-inline">
            <option value="Paris">Paris</option>
            <option value="Philadelphia">Philadelphia</option>
            <option value="Boston">Boston</option>
            <option value="Portland">Portland</option>
            <option value="San Diego">San Diego</option>
            <option value="Mexico City">Mexico City</option>
            <option value="São Paolo">São Paolo</option>
        <h2>Choose your destination city:</h2>
        <select name="toPort" class="form-inline">
            <option value="Buenos Aires">Buenos Aires</option>
            <option value="Rome">Rome</option>
            <option value="London">London</option>
            <option value="Berlin">Berlin</option>
            <option value="New York">New York</option>
            <option value="Dublin">Dublin</option>
            <option value="Cairo">Cairo</option>

    I am using but it is capturing all the drop-down values from different drop-down list. I need values to be separated by fields

  • Be aware that using Regular Expressions for extracting values from HTML responses might not be the best idea as:

    • Regular expressions would be hard to create and maintain
    • Regular expressions will be very sensitive to markup change, i.e. new line or attribute order will run your test

    I would recommend going for CSS/JQuery Extractor instead

    1. Add CSS/JQuery Extractor as a child of the request
    2. Configure it as follows:

      • Name of created variable: anything meaningful, i.e. from
      • CSS/JQuery expression: select[name=fromPort] > option
      • Attribute: value
      • Match No. -1
    3. It will generate the following matches:

      JMeter CSS/JQuery Extractor Matches

    4. Resulting in the next JMeter Variables

      JMeter CSS Jquery Extractor Generated Variables

    5. Now you will be able to refer them as:

      • ${from_1} - will result in Paris
      • ${from_2} - will return Philadelphia
      • etc.

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2