XPath2 Variable Extractor¶
XPath2 Variable Extractors lets you extract variables from HTML/XML responses using XPath2 queries.
Extracting variables from HTTP response helps you make your Virtual User have a dynamic behavior. Extracted variables can be injected in Logic Actions or HTTP Request Actions.
The first line displays the extracted variable name. This field is mandatory if you want to inject what you extract. The second line contains tab headers to access:
- Configuration, for more specific needs,
- Check, to validate the result of your XPath2 against an HTTP response.
The response selector, on the right, lets you choose which HTTP response is used for configuring and checking the XPath2 Action. So if neither recorded responses nor Validate VU responses are available, you have to configure the XPath2 Action blindly.
To configure a XPath2 extractor, the procedure is as follows:
- Fill the XPath 2.0 query field with a proper XPath expression,
- Select the Match number if your expression yields more than one result,
- Add a namespace. In our example
http://www.w3.org/1999/xhtmlwith no prefix (as seen on line 21 in the HTML). But you will have to adapt this to your use case.
You can use third party tools like XPather to accelerate the design of your XPath expression. Just copy and paste the content of the response displayed on this page.
To check the result of a XPath2 action just click on the Check tab.
The check process is automatically launched when this tab is opened. It can also be manually started using the Refresh button.
A table contains the extracted values :
|Extracted variable name||The name of the extracted variable. A single XPath2 Action can lead to multiple extracted variables. More information below.|
|Extracted variable value||The value of the extracted variable.|
Multiple variables can be generated by a single XPath2 Action.
E.g. using the following HTML body :
<form method="post" action="/actions/Catalog.action"> <input name="keyword" type="text" /> <input name="searchProducts" type="submit" value="Search" /> <input type="hidden" name="_sourcePage" value="8UhFy3GTVvJLzGIdfPyNqtoclan" /> </form> <form method="post" action="/actions/Account.action"> Please enter your username and password. Username:<input name="username" type="text" /> Password:<input name="password" type="password" /> <input name="signon" type="submit" value="Login" /> <input type="hidden" name="_sourcePage" value="o_adZEJ7UO8IhGgRmltu2Ra6rSr" /> </form>
sourcePagewith the XPath2 path value
Select Nthmatch number:
sourcePage: the base variable, it contains the extracted value (or the default value), e.g.
All match number, multiple variables are generated :
sourcePage: the default value as specified on the advanced tab,
sourcePage_N: the Nth value extracted,
sourcePage_matchNr: the number of values extracted, e.g. 2.
An extracted variable without name cannot be used for value injection.