0

I have a html select like below

<select id="alias" name="alias">
  <option value="">-Select-</option>
  <option
          value='100'
          data-accountnumber='2251106207001'
          data-accountholder='Ashraful'
          data-mobilenumber='01811449003'
          data-email='shadiq2@yahoo.com'>
      testBeneficiary-1
  </option>
</select>

I need a regular expression for JMeter to extract the value which is 100 of above snippet. Can anyone help me with this? Thanks in advancet

silk_route11
  • 324
  • 3
  • 17

2 Answers2

1

As per https://stackoverflow.com/a/1732454/2897748

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.

I would suggest using XPath Extractor instead.

In your case XPath Extractor should be configured as follows:

  • Check Use Tidy if data isn't XML/XHTML compliant, elsewise you'll get SAX Exception
  • Reference Name: anything meaningful, it will be the name of JMeter Variable storing XPath Expression Result. Let it be value
  • XPath Query:

    //select[@id='alias']/option[@data-email='shadiq2@yahoo.com']/@value
    

The XPath query above returns "value" attribute of option which "data-email" attribute is "shadiq2@yahoo.com" of select with "alias" id.

Once extracted you will be able to refer that variable as ${value} or ${__V(value)}

See Using the XPath Extractor in JMeter guide for more details, XPath language reference and short cookbook.

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
1

The given html text

<select id="alias" name="alias">
  <option value="">-Select-</option>
  <option
          value='100'
          data-accountnumber='2251106207001'
          data-accountholder='Ashraful'
          data-mobilenumber='01811449003'
          data-email='shadiq2@yahoo.com'>
      testBeneficiary-1
  </option>
</select>

We can get the option value 100 using the following regex formats

Regex formats to get the value 100

<option value="">-Select-</option>\s\s\s<option\s\s\s\s\s\s\s\s\s\s\svalue='(.+)'

Note :

\s - means single space
\s\s\s - means three spaces
\s\s\s\s\s\s\s\s\s\s\s - means eleven spaces