Home > Automation Testing > How to use XPath Extractor in JMeter?

How to use XPath Extractor in JMeter?

XPath extractor is post processor component of JMeter. XPath extractor extracts text from the HTML response based on XPath query provided.
To use XPath extractor in the Test plan we need to add it as a child element of HTTP Request sampler.
Example to use XPath Extractor in JMeter Test plan

Step 1: Add Thread Group to the Test plan and configure as shown below

Image: Thread Group

Step 2: Add HTTP Request sampler to the Test plan and configure it as shown in below image.

Image: HTTP request sampler

Step 3: Add Xpath Extractor post processor as child element of HTTP request sampler

Image: XPath Extractor

Step 4: Configure the newly added XPath Extractor as shown below

Image: XPath Extractor Configuration

Step 5: Add Beanshell post processor as child element of HTTP request sampler. It will help to display the xpath value to the console

Image: Beanshell Post Processor

Fields in XPath Extractor
Name: User can give any convenient name to the XPath extractor.
Name of created variable: Result will be stored in this variable.
XPath query: User can mention the xpath query. It can return more than one match.
Match No: If XPath query returns more than one match then user needs to specify required match no.
Default Value: If no match is found by the XPath query then default value is used.
Return entire XPath fragment instead of text content?: If unchecked then XPath query returns only the text value which is matched. If checked then XPath query returns entire XPath fragment. 

If ‘Return entire XPath fragment instead of text content?’ is checked then following output is seen

Image: XPath fragment checked

If ‘Return entire XPath fragment instead of text content?’ is unchecked then following output is seen

Image: XPath fragment unchecked
This Article is TAGGED in , , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">