{"id":795,"date":"2016-04-20T10:37:44","date_gmt":"2016-04-20T10:37:44","guid":{"rendered":"https:\/\/loadfocus.com\/blog\/?p=795"},"modified":"2022-08-04T11:47:58","modified_gmt":"2022-08-04T11:47:58","slug":"how-to-use-apache-jmeters-xpath-extractor","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/2016\/04\/how-to-use-apache-jmeters-xpath-extractor","title":{"rendered":"How to Use Apache JMeter&#8217;s XPath Extractor?"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span><p class=\"lead\">In order to add an XPath Extractor to your JMeter script you need to&nbsp;begin by <a href=\"https:\/\/loadfocus.com\/blog\/2016\/04\/13\/how-to-use-apache-jmeter-to-load-test-a-web-server\/\">installing JMeter<\/a> and create an HTTP Request. If you want to check <a href=\"https:\/\/loadfocus.com\/blog\/2016\/04\/13\/how-to-use-apache-jmeter-to-load-test-a-web-server\/\">how you can create a load test with Apache JMeter<\/a>, please check our previous blog post.<\/p>\n<p>Start by adding a XPath Extractor to your HTTP Request&nbsp;by following the below steps:<\/p>\n<ul>\n<li>Select&nbsp;the<em> HTTP Request<\/em>&nbsp;on the left side, and Right-click it<\/li>\n<li>Hover to <em>Add -&gt; Post Processors&nbsp;-&gt;&nbsp;XPath Extractor<\/em><\/li>\n<li>Click on<em> <em>XPath Extractor<\/em><\/em><\/li>\n<\/ul>\n<p><img loading=\"lazy\" width=\"972\" height=\"481\" class=\"aligncenter size-full wp-image-799\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/adding-xpath-extractor.png\" alt=\"adding-xpath-extractor\"><\/p>\n<p>Update the XPath Extractor with the desired variable names and expected XPath. We are going to make an HTTP Request to&nbsp;https:\/\/example.com\/ and based on the HTML response, we are going to extract the H1 tag from the website and use it in the next request.<\/p>\n<p>Update the XPATH Extractor with the following details:<\/p>\n<ul>\n<li><strong>Reference Name<\/strong>: The name of the JMeter variable in which to store the result,&nbsp;<strong>var1<\/strong><\/li>\n<li><strong>XPath Query<\/strong>: Element query in XPath language. Can return more than one match,&nbsp;<strong>\/\/html\/\/h1<\/strong><\/li>\n<li><strong>Default Value<\/strong>: Default value returned when no match found. It is also returned if the node has no value and the fragment option is not selected,&nbsp;<strong>NOTFOUND<\/strong><\/li>\n<\/ul>\n<p><img loading=\"lazy\" width=\"806\" height=\"437\" class=\"aligncenter size-medium wp-image-801\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/configure-xpath-extractor-jmeter.png\" alt=\"configure-xpath-extractor-jmeter\"><br \/>\n           \r\n            <div class=\"onp-locker-call\" style=\"display: none;\" data-lock-id=\"onpLock303576\">\r\n                <p>\nCopy the existing HTTP Request and add the variable in the Server Name:<\/p>\n<ul>\n<li><em>www.example.com\/${var1}<\/em><\/li>\n<\/ul>\n<p><img loading=\"lazy\" width=\"607\" height=\"63\" class=\"aligncenter size-medium wp-image-804\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/update-new-http-request-jmeter.png\" alt=\"update-new-http-request-jmeter\"><\/p>\n<p>In the View Results Tree, you can see that the variable var1 contains the content extracted from the XPATH&nbsp;<strong>\/\/html\/\/h1,&nbsp;<\/strong>&nbsp;<strong>Example Domain<\/strong>, and the second request is going to be:<\/p>\n<ul>\n<li><em>GET https:\/\/www.example.com\/Example Domain\/<\/em><\/li>\n<\/ul>\n<p><img loading=\"lazy\" width=\"1079\" height=\"342\" class=\"aligncenter size-medium wp-image-802\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-xpath-extracted-variable.png\" alt=\"jmeter-xpath-extracted-variable\"><\/p>\n<p><img loading=\"lazy\" width=\"794\" height=\"419\" class=\"aligncenter size-medium wp-image-803\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/result-from-xpath-extractor.png\" alt=\"result-from-xpath-extractor\"><\/p>\n<p>Have in mind that you can check the XPath also from inside the browser&#8217;s console, by typing the following:<\/p>\n<pre class=\"lang-java\"><code> $x('\/\/html\/\/h1') \n<\/code><\/pre>\n<p>which should output the element&#8217;s&nbsp;content that was saved inside the <strong>${var1}<\/strong> variable from XPath Extractor.<\/p>\n<p><img loading=\"lazy\" width=\"885\" height=\"858\" class=\"aligncenter size-medium wp-image-800\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/chrome-browser-console-xpath.png\" alt=\"chrome-browser-console-xpath\">\n<\/p>\r\n            <\/div>\r\n         \r\n\r\n        <br \/>\nIn order to run load tests with thousands of threads (users) and to run load tests from different world locations, you can use <a href=\"https:\/\/loadfocus.com\">LoadFocus.com<\/a> which offers a cloud load testing service, easy to use, which keeps all your tests and test runs in the history automatically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>In order to add an XPath Extractor to your JMeter script you need to&nbsp;begin by installing JMeter and create an HTTP Request. If you want to check how you can create a load test with Apache JMeter, please check our previous blog post. Start by adding a XPath Extractor to your HTTP Request&nbsp;by following the&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/2016\/04\/how-to-use-apache-jmeters-xpath-extractor\" class=\"more-link\" title=\"Read How to Use Apache JMeter&#8217;s XPath Extractor?\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,48],"tags":[135,134],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/795"}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/comments?post=795"}],"version-history":[{"count":0,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/795\/revisions"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media?parent=795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/categories?post=795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/tags?post=795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}