2

THIS IS MY HTML CODE.

  <select name="account.languagePreference"><option value="english">english</option>
<option value="japanese">japanese</option></select>

<select name="account.favouriteCategoryId"><option value="FISH">FISH</option>
<option value="DOGS">DOGS</option>
<option value="REPTILES">REPTILES</option>
<option value="CATS">CATS</option>
<option value="BIRDS">BIRDS</option></select>

Question :- i want Regular expression for second dropdown list (answer should be like this as mention below)

 Match[][]=FISH
 Match[][]=DOGS
 Match[][]=REPTILES
 Match[][]=CATS
 Match[][]=BIRDS

please help me i am not able to extract complete matching.

i have used regex as

<select name="account.favouriteCategoryId">.+|\s+<option value="(.*?)">.*?</option>.+|\s+</select>

and getting o/p as

Match count: 6
Match[1][0]= 
<option value="japanese">japanese</option></select></td>
Match[1][1]=japanese
  Match[2][0]=<select name="account.favouriteCategoryId"><option value="FISH">FISH</option>
Match[2][1]=null
Match[3][0]=
<option value="DOGS">DOGS</option>
Match[3][1]=DOGS    
Match[4][0]=
<option value="REPTILES">REPTILES</option>
Match[4][1]=REPTILES
Match[5][0]=
<option value="CATS">CATS</option>
Match[5][1]=CATS
Match[6][0]=
<option value="BIRDS">BIRDS</option></select></td>  
    Match[6][1]=BIRDS

But i want as mention on top (only values of second dropdown list)

thanks

Shubham
  • 33
  • 6

2 Answers2

3

Use Post processor CSS/JQuery Extractor with the following:

Reference Name: category (the variable )
CSS/Jquery expression: select[name=account.favouriteCategoryId]> option

Match No. -1 (return all options)

You will get the variables:

category_1=FISH
category_2=DOGS
category_3=REPTILES
category_4=CATS
category_5=BIRDS

You can do it in Regular Expression Extractor using:

Regular Expression: favouriteCategoryId">(([\S\s]*)<option value="([^"]+)*">(\w+)<\/option>([ \s\t\n]+)([\S\s]*)+)

Match No: -1 (to get all)
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
3

It is not recommended to use regular expressions for parsing HTML, I would suggest going for XPath Extractor instead.

  1. Add XPath Extractor as a child of the request which returns the above HTML
  2. Configure it as follows:

    • Reference Name: anything meaningful, i.e. option
    • XPath expression: //select[@name='account.favouriteCategoryId']/option/@value
    • If response is not XTML/HTML-compliant check Use Tidy box

Demo:

XPath Extractor Demo

References:

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