简体   繁体   English

JMeter中的XPath查询

[英]XPath Query in JMeter

I'm currently working with JMeter in order to stress test one of our systems before release. 我目前正在与JMeter合作,以便在发布之前对我们的系统之一进行压力测试。 Through this, I need to simulate users clicking links on the webpage presented to them. 这样,我需要模拟用户单击呈现给他们的网页上的链接。 I've decided to extract theese links with an XPath Post-Processor. 我决定使用XPath后处理器提取这些链接。

Here's my problem: 这是我的问题:

I have an a XPath expression that looks something like this: 我有一个XPath表达式,看起来像这样:

//div[@data-attrib="foo"]//a//@href

However I need to extract a specific child for each thread (user). 但是我需要为每个线程(用户)提取一个特定的子代。 I want to do something like this: 我想做这样的事情:

//div[@data-attrib="foo"]//a[position()=n]//@href

(n being the current index) (n是当前索引)

My question: 我的问题:

Is there a way to make this query work, so that I'm able to extract a new index of the expression for each thread? 有没有一种方法可以使此查询正常工作,以便能够为每个线程提取表达式的新索引?

Also, as I mentioned, I'm using JMeter. 另外,正如我提到的,我正在使用JMeter。 JMeter creates a variable for each of the resulting nodes, of an XPath query. JMeter为XPath查询的每个结果节点创建一个变量。 However it names them as "VarName_n", and doesn't store them as a traditional array. 但是它将其命名为“ VarName_n”,并且不将其存储为传统数组。 Does anyone know how I can dynamicaly pick one of theese variables, if possible? 有谁知道我如何可以动态地选择这些变量之一? This would also solve my problem. 这也可以解决我的问题。

Thanks in advance :) 提前致谢 :)

EDIT: 编辑:

Nested variables are apparently not supported, so in order to dynamically refer to variables that are named "VarName_1", VarName_2" and so forth, this can be used: 显然不支持嵌套变量,因此为了动态引用名为“ VarName_1”,“ VarName_2”等的变量,可以使用:

${__BeanShell(vars.get("VarName_${n}"))}

Where "n" is an integer. 其中“ n”是整数。 So if n == 1, this will get the value of the variable named "VarName_1". 因此,如果n == 1,将获得名为“ VarName_1”的变量的值。

If the "n" integer changes during a single thread, the ForEach controller is designed specifically for this purpose. 如果在单个线程中“ n”整数发生变化,则ForEach控制器是专门为此目的而设计的。

For the first question -- use : 对于第一个问题-使用

(//div[@data-attrib="foo"]//a)[position()=$n]/@href 

where $n must be substituted with a specific integer. $ n必须用特定的整数代替。

Here we also assume that //div[@data-attrib="foo"] selects a single div element. 这里我们还假设//div[@data-attrib="foo"]选择单个div元素。

Do note that the XPath pseudo-operator // typically result in very slow evaluation (a complete sub-tree is searched) and also in other confusing problems ( this is why the brackets are needed in the above expression). 请注意,XPath伪运算符//通常会导致非常缓慢的评估(搜索完整的子树)和其他令人困惑的问题(这就是为什么在上面的表达式中使用括号的原因)。

It is recommended to avoid using // whenever the structure of the document is known and a complete, concrete path can be specified . 建议避免在知道文档结构并可以指定完整的具体路径时使用//

As for the second question, it is not clear. 至于第二个问题,目前还不清楚。 Please, provide an example. 请提供一个例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM