如何在 JMeter 中通过 XPath Extractor 提取响应?
我得到如下响应:
<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>
我已经将 Xpath 提取器添加到采样器中:
Reference name: mytest
XPath Query: //test[@id='1']
但返回变量 (mytest) 是错误的。
OUT.println(mytest) --> void
我是 JMeter 的新手。我能做什么来解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,
println()
函数打印了test
元素的字符串值,而在提供的XML文档中,test
元素没有任何内容,并且它们的字符串值为空字符串。您想要:
并且
前者选择文档顶部元素的所有
test
孙子元素的所有name
属性,这些属性具有id值为
属性。1
的后者选择文档顶部元素的所有
test
孙子元素的所有status
属性,这些属性的id
属性值为1
。Obviously the
println()
function prints the string value of thetest
element, and in the provided XML documenttest
elements do not have any content and their string value is the empty string.You want:
and
The former selects all
name
attributes of alltest
grandchildren of the top element of the document, that have anid
attribute with value1
.The latter selects all
status
attributes of alltest
grandchildren of the top element of the document, that have anid
attribute with value1
.可能是因为您没有文字内容。尝试设置“
返回整个 XPath 片段而不是文本内容?
”It could be because you have no text content. Try setting "
Return entire XPath fragment instead of text content?
"