如何在 JMeter 中通过 XPath Extractor 提取响应?

Hoà*_*ong 4 xpath web-testing jmeter beanshell

我得到如下响应:

<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>
Run Code Online (Sandbox Code Playgroud)

我已经在采样器中添加了一个 Xpath 提取器:

Reference name: mytest
XPath Query: //test[@id='1']
Run Code Online (Sandbox Code Playgroud)

但是返回变量(mytest)是错误的。

OUT.println(mytest) --> void
Run Code Online (Sandbox Code Playgroud)

我是 JMeter 的新手。我能做些什么来解决这个问题?

Dim*_*hev 5

我已经在采样器中添加了一个 Xpath 提取器:

参考名称:mytest XPath 查询:

//test[@id='1'] 
Run Code Online (Sandbox Code Playgroud)

但是返回变量(mytest)是错误的。

OUT.println(mytest) --> void
Run Code Online (Sandbox Code Playgroud)

显然该println()函数打印test元素的字符串值,并且在提供的 XML 文档中test元素没有任何内容,它们的字符串值是空字符串。

你想要

/*/*/test[@id=1]/@name
Run Code Online (Sandbox Code Playgroud)

/*/*/test[@id=1]/@status
Run Code Online (Sandbox Code Playgroud)

前者选择文档顶部元素name的所有test孙子元素的所有属性,这些id属性的属性值为1

后者选择文档顶部元素status的所有test孙子元素的所有属性,这些id属性的属性值为1