Search code examples
htmlparsingxpathjmeter

How to to extract attribute from response by XPath Extractor in JMeter?


I need get attr. values componentId and interactionstate from html via JMeter, i try with XPath extractor but I can`t do that.

<html>
    <body>
        ...
        <form ...>
        <form class="UIForm" id="UINavigationComposer" action="/portal/intranet/home?portal:componentId=d934d0f3-d465-4c1d-880a-45f54b3c48e2&amp;interactionstate=JBPNS_rO0ABXcwAAt1aWNvbXBvbmVudAAAAAEAFFVJTmF2aWdhdGlvbkNvbXBvc2VyAAdfX0VPRl9f&amp;portal:type=action" method="post">
        <form ...>
        ...
    </body>
</html>

I try to use xpath query:

/html/body/form@[id=UINavigationComposer]/@action

but obtain error:

Assertion failure message: /html/body/form@[id=UINavigationComposer]; => The reference to entity "portal:action" must end with the ';' delimiter.


Solution

  • I think you have a little lapse in your xpath query. Put @ near the id attribute like below

    /html/body/form[@id=UINavigationComposer]/@action
    

    or use something like this:

    //form[@id='UINavigationComposer']/@action
    

    So, the first step - to extract full action value and store it in separate jmeter variable (e.g. ACTION_TEST), using either RegEx or Xpath Extractor.
    The second step - to extract from this variable values for componentId and interactionstate.
    RegEx Extractor in jmeter 2.5 (since 2.3.2, afair) has option "Apply to ... Jmeter Variable".
    You can add 2 additional RegEx Extractors each with ${ACTION_TEST} in "Apply to ... Jmeter Variable" option and correcponding queries:

    componentId=(.+?);
    interactionstate=(.+?);
    
    1. Extractor to get full action value FROM RESPONSE + save to variable.
    2. Extractor to get componentId value FROM VARIABLE.
    3. Extractor to get interactionstate value FROM VARIABLE.

    Hope this will work.