0

From the HTML code I have to fetch value based on variable passed and option selected. for an example please refer below code:

I have Test F as a variable, using regex extractor I have to fetch value 6666666. Also can we check using regex while fetching value whether variable option is selected or not? I am beginner and learning regex. Please help with regular expression needed.

<option value="11111111">TestA</option>
<option value="22222222">TestB</option>
<option value="33333333">TestC</option>
<option value="44444444">TestD</option>
<option value="55555555">Test E</option>
<option selected="selected" value="6666666">Test F</option>
<option value="77777777">Test G</option>
Karry
  • 33
  • 1
  • 1
  • 5
  • you must get `selected` option? if not what you expect exactly to happen? – Ori Marko Oct 24 '18 at 07:05
  • I have to fetch value of Test F and also want to check whether it is selected = "selected". If above thing is not valid or cant be done then I just need to fetch value of Test F i..e in above example it is 6666666 – Karry Oct 24 '18 at 07:07

1 Answers1

0

Using regular expressions for parsing HTML is not the best way to proceed, I would recommend going for XPath Extractor instead

  1. To check whether Test F option is selected or not:

    //option[text()='Test F']/@selected
    

    JMeter xpath selec attribute

  2. To fetch selection value:

     //option[text()='Test F']/@value
    

    JMeter XPath selection attribute value

  3. You can replace Test F with the JMeter Variable reference:

     //option[text()='${YOUR_VARIABLE_HERE}']/@value
    
  4. You can combine 2 or more expressions using | operator

    JMeter xpath combine

More information:

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