> OctoPerf load testing - XPath1 Variable Extractor documentation page. XPath1 Variable Extractors lets you extract variables from server responses using XPath1 queries.

Source: https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/xpath1-variable-extractor/

# XPath1 Variable Extractor

XPath1 Variable Extractors lets you **extract variables from HTML/XML responses** using [XPath1 queries](https://www.w3schools.com/xml/xpath_syntax.asp).

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.

!!! warning
    XPath1 should be avoided for HTML extractions, [CSS Selector Extractor](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/css-variable-extractor/) is the correct and performing solution. Also, since JMeter 5.0 (september 2018) you should use [XPath2 Extractor](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/xpath2-variable-extractor/) as it provides better and easier namespace management, better performances and support for XPath 2.0.

![Header XPath1 Extractor](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/xpath1.png "Header XPath1 Extractor")

| Field            | Description                                                  |
| ---------------- | ------------------------------------------------------------ |
| Name             | Name of the variable created by this processor. Can be used with the `${...}` syntax like any other variable. |
| From             | This is for information purpose since this processor can only extract from **Response body**. |
| Include XML Tags | This option will return the entire XPath fragment instead of the text. Use it when you're not simply extracting a single attribute. |
| Query            | The [XPath Query](https://www.w3schools.com/xml/xpath_syntax.asp) to be used. |
| Default value    | If no value is found, the variable will be equal to this. With match number **All**, you get the default value if you do not provide an index number. |
| Match number     | Lets you choose how to deal with the processor having several results (or occurrences). Selecting **All** will change the behavior of your processor, see [the dedicated section of the regex page](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/regexp-variable-extractor/#multiple-occurrences) for more details. |

## Parser settings

### Strict

It is possible to use two different parsers for your XPath expressions, the first one uses the Xalan XPath parser, **it should be used on proper XML content only**.

![XPath1 strict settings configuration](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/xpath1-settings-strict.png "XPath1 Extractor strict settings configuration"){ align=left }

| Name               | Description                                                  |
| ------------------ | ------------------------------------------------------------ |
| Use namespace      | If active, provide the namespace file and [add this user property](https://api.octoperf.com/doc/design/edit-virtual-user/configuration/files/#properties) : `xpath.namespace.config=namespaces.properties` |
| Validate XML       | Activates [document validation](https://www.w3schools.com/xml/xml_validator.asp). |
| Ignore whitespaces | Ignore [Element Whitespace](https://www.tutorialspoint.com/xml/xml_white_spaces.htm). |
| Download DTDs      | If selected, external [DTDs](https://www.w3schools.com/xml/xml_dtd.asp) are fetched. |

### Tolerant

The second one uses [Tidy](http://jtidy.sourceforge.net/) to convert HTML to XML beforehand. **This option should be used when working on HTML content**, or any non-XML format that requires proper conversion beforehand.

![XPath1 tolerant settings configuration](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/xpath1-settings-tolerant.png "XPath1 Extractor tolerant settings configuration"){ align=right }

| Name          | Description                                                  |
| ------------- | ------------------------------------------------------------ |
| Quiet         | If enabled, limits the output to only document warnings and errors. |
| Report errors | If a Tidy error occurs, then set the Assertion accordingly.  |
| Show warnings | This option specifies if Tidy should display warnings.       |

!!! warning
    Tidy will convert all elements and attribute names to lowercase.
    Tidy also attempts to correct improperly nested elements. Check [its documentation](http://jtidy.sourceforge.net/) for more info.

## Debug

In order to validate the results of your extraction, you can use the debug panel.

![debug-processor](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/img/debug-processor.png)

The procedure is explained on the [regex extractor page](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/regexp-variable-extractor/#debug) for both simple and multiple occurrences.

## Example

### From a browser

In this example we will be using the [login page from our Petstore](https://petstore.octoperf.com/actions/Account.action?signonForm=) application. Make sure to import an HAR recording of this page.

The first step will be to navigate to this page and use the **Right-click + Inspect** menu of our browser to locate the element we want to extract:

![XPath Extractor check](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/xpath-copy-xpath.png "XPath Extractor check")

Using the **Copy XPath** function we can get:

```xquery
//*[@id="Catalog"]/form/div/input[1]
```

We can copy this directly in our **XPATH1 extractor** in OctoPerf, just adding on top of it that we want to extract the content of the **value** attribute with `/@value`:

```xquery
//*[@id="Catalog"]/form/div/input[1]/@value
```

### Simpler expression

Alternatively we could also rework our XPath Query to something simpler like:

```xquery
//input[@name='_sourcePage']/@value
```

![XPath1 debug](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/img/xpath1-debug.png)

We would then pick only inputs named `_sourcePage` and this would be less dependent on the page structure. So provided the name is unique to this parameter we can get a more resilient expression if the application ever changes.

!!! tip
    You can use third party tools like [XPather](http://xpather.com/) to accelerate the design of your XPath expression. Just copy and paste the content of the response displayed on this page.
