0

I have a query regarding Jmeter regex extractor. I am trying to implement 1 scenario however not able to do same. Below are the details:

Requirement :

In Jmeter I have defined user defined variable : String VAR = KZ

now I am trying to use Regex extractor so that from the HTML response, regex will match VAR value in HTML(defined below) and will fetch span class name, as I need to set checkbox ON for KZ.

Requirement is to handle checkbox ON functionality through user defined variable, that means I don't want to hardcode class name instead based on user defined variable(which will be td value i.e. in this example KZ) I have to fetch class name using Regex Extractor. Could someone please help how to proceed?

Below is HTML Code:

<tr class="trClass">
<td style="width: 13.5%;">
<span class="checkbox"><input id="ctl00ctl94" type="checkbox" name="$ctl95$" 
 onclick="return validatecheck();" /></span>
</td>
<td style="width: 41.2%;"> KZ </td>
<td style="width: 0%; display: none;"> 5581357 </td>
<td style="width: 32%;"> 06/03/2018 2:22:38 PM </td>
</tr>
<tr class="trClass">
<td style="width: 13.5%;">
<span class="checkbox"><input id="ctl00ctl95" type="checkbox" name="$ctl95$" 
onclick="return validatecheck();" /></span>
</td>
<td style="width: 41.2%;"> TM </td>
<td style="width: 0%; display: none;"> 5581358 </td>
<td style="width: 32%;"> 06/03/2018 2:22:38 PM </td>
</tr>
<tr class="trClass">
<td style="width: 13.5%;">
<span class="checkbox"><input id="ctl00ctl96" type="checkbox" name="$ctl96$" 
onclick="return validatecheck();" /></span> </td>
<td style="width: 41.2%;">TR </td>
<td style="width: 0%; display: none;"> 5581359  </td>
<td style="width: 32%;"> 06/03/2018 2:22:38 PM  </td>
</tr>
Karry
  • 33
  • 1
  • 1
  • 5

1 Answers1

0

Using regular expressions for parsing HTML is not the best idea as:

  • they are hard to develop and/or maintain
  • they are very sensitive to markup change hence fragile, i.e. if order of attributes changes or something will go to a new line - it will simply ruin your regex

So I would recommend going for another post-processor which can work with DOM directly, for instance XPath Extractor

The relevant XPath query which will fetch the classname of span which is above the KZ text would be something like:

//td[contains(text(),'KZ')]/preceding::*/span/@class

JMeter View Results Tree

Of course you can substitute KZ with the JMeter Variable reference, i.e.

//td[contains(text(),'${VAR}')]/preceding::*/span/@class

However you will not be able to test your queries using XPath Tester mode of the View Results Tree listener, you will have to go for Debug Sampler instead to visualize the resulting variable.

Check out XPath Tutorial and Using the XPath Extractor in JMeter guide to get familiarized with XPath language.


Also be aware that according to JMeter project main page:

JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages.

So I don't believe fetching the span classname will solve your problem, most probably you will need to send underlying input name as a parameter so you should be looking for

//td[contains(text(),'KZ')]/preceding::*/span/input/@name 
Dmitri T
  • 159,985
  • 5
  • 83
  • 133