4

I got the response like the following:

<response>
  <status code='200' server_time='xxx' />
  <tests>
    <test id='1' name='a!' status='Started' />
    <test id='2' name='bb!' status='New' />
    <test id='3' name='ccc!' status='New' />
    <test id='4' name='dddd!' status='New' />
  </tests>
</response>

I have already added a Xpath extractor into the sampler:

Reference name: mytest
XPath Query: //test[@id='1']

But the return variable (mytest) is wrong.

OUT.println(mytest) --> void

I'm a newbie with JMeter. What can I do to solve this?

Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
  • This JMeter Xpath Extractor Guide should help you to get familiar with XPath Expressions: https://octoperf.com/blog/2018/04/10/jmeter-xpath-extractor/ – Jerome L Apr 10 '18 at 14:24

2 Answers2

5

I have already added a Xpath extractor into the sampler:

Reference name: mytest XPath Query:

//test[@id='1'] 

But the return variable (mytest) is wrong.

OUT.println(mytest) --> void

Obviously the println() function prints the string value of the test element, and in the provided XML document test elements do not have any content and their string value is the empty string.

You want:

/*/*/test[@id=1]/@name

and

/*/*/test[@id=1]/@status

The former selects all name attributes of all test grandchildren of the top element of the document, that have an id attribute with value 1.

The latter selects all status attributes of all test grandchildren of the top element of the document, that have an id attribute with value 1.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • @Dimitre: excuse me, but it still not work. I have tried @id="1" as well, but nothing happens. – Hoàng Long Feb 23 '11 at 03:17
  • @Hoàng-Long: This means that either you are evaluating the XPath expressions against some other XML document with different structure/names or that you are using a non-compliant XPath engine. I would recommend to use the XPath Visualizer (http://www.huttar.net/dimitre/XPV/TopXML-XPV.html) and refine your XPath expression until it selects exactly what you want. – Dimitre Novatchev Feb 23 '11 at 03:29
  • @Dimitre: thanks, I have figured it out. The problem is that I use tidy mode, and somehow it stops XPath Extractor from getting the value. Many thanks for the expression, though :) – Hoàng Long Feb 23 '11 at 10:16
2

It could be because you have no text content. Try setting "Return entire XPath fragment instead of text content?"

dogbane
  • 266,786
  • 75
  • 396
  • 414