2

Here is the sample view

<a class="main mainAnchor current currentAnchor" tabindex="-1" href="Form1">
            <span>Home</span>
<a class="main mainAnchor parent parentAnchor" tabindex="-1" href="Form2">
<span>About Us</span>
<a class="sub subAnchor" tabindex="-1" href="Form3">
                <span>Landing</span>

<a class="sub subAnchor" tabindex="-1" href="Form4">
                <span>Contact Us</span>

<a class="sub subAnchor" tabindex="-1" href="Form5">
                <span>Hours &amp; Map</span
In Jmeter i am using the regular expression as
(<a)\s+(class="(.+?)")\s+(tabindex="-1")\s+(href="(.+?)")>(\n|\r)\s+(<span>)(.+)

Using above regular Expression i am getting totol of 58 matchs here is the sample result for regular expresion Match count: 58

Match[1][0]=<a class="main mainAnchor current currentAnchor" tabindex="-1" href="Form1">
                <span>some text</span>
    Match[1][1]=<a
    Match[1][2]=class="some text"
    Match[1][3]=some text
    Match[1][4]=tabindex="-1"
    Match[1][5]=href="Form1"
    Match[1][6]=Form1
    Match[1][7]=

    Match[1][8]=<span>
    Match[1][9]=some text</span>
    Match[2][0]=<a class="main mainAnchor parent parentAnchor" tabindex="-1" href="Form2">
                <span>some text</span>
    Match[2][1]=<a
    Match[2][2]=class="some text"
    Match[2][3]=some text
    Match[2][4]=tabindex="-1"
    Match[2][5]=href="Form2"
    Match[2][6]=Form2
    Match[2][7]=

    Match[2][8]=<span>
    Match[2][9]=About Us</span>
    Match[3][0]=<a class="sub subAnchor" tabindex="-1" href="Form3">
                    <span>some text</span>
    Match[3][1]=<a
    Match[3][2]=class="sub subAnchor"
    Match[3][3]=sub subAnchor
    Match[3][4]=tabindex="-1"
    Match[3][5]=href="Form3"
    Match[3][6]=Form3
    Match[3][7]=

    Match[3][8]=<span>
    Match[3][9]=some text</span>

and i am able to get the first value like this referenceName_g6 i want to retrive all the values of attribute href Form2,Form3,Form4 ...etc After getting the values i want to pass this(referenceName_g6) one by one value to Path value of next http request Please help on this... Thanks in advance..

Users9949
  • 1,819
  • 1
  • 12
  • 11

1 Answers1

0
  1. It might be easier use XPath Extractor or CSS JQuery Extractor instead of regular expressions. In general parsing HMTL with regular expressions isn't a very good idea. Example XPath Extractor configuration would look like:

    • If response is not XHTML-compliant check Use Tidy box
    • Reference Name: anything meaningful, i.e. Form - it will be result variable name/prefix
    • XPath Expresssion: //a[contains(@class, "Anchor")]/@href - it extracts "href" attribute of all links having "Anchor" test in "class"

    Xpath Extractor

  2. In order to dynamically construct the next request path add a Beanshell PreProcessor as a child of the next request and add the following code into it's "Script" area

    Iterator it = vars.getIterator();
    while (it.hasNext()) {
        Map.Entry var = (Map.Entry) it.next();
        log.info("Processing variable: " + var.getKey());
        if (var.getKey().toString().startsWith("Form")) {
            sampler.addArgument(var.getKey(), var.getValue().toString());
        }
    }
    

    Above code will add all the variables names which names start with "Form" as request parameters names and variables values will be parameters values. See How to Use BeanShell: JMeter's Favorite Built-in Component guide for extra information on using Beanshell in your JMeter test.

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank a lot Dmitri.How to pass the Xpath Reference name to Bean shell processor script. out put of Xpath Extractor i like this siteMapName_1=HomePage siteMapName_10=Reviews siteMapName_19=ContactUs siteMapName_2=LandingPage – Users9949 Nov 30 '15 at 14:09
  • Replace `startsWith("Form")` with `startsWith("siteMapName")` – Dmitri T Nov 30 '15 at 16:37