1

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>
    </select>
    <p>
    <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>
    </select>

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

1 Answer 1

3

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.
1
  • Thanks a lot for your help sir. Yes it does work. CaN we use it for below as well? <input type="hidden" value="43" name="flight"> <input type="hidden" value="472.56" name="price"> <input type="hidden" value="Virgin America" name="airline"> Oct 3, 2018 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.