[英]validate XPath in JMeter Groovy Script
I want the value of meta keywords and it returns null in both the cases我想要元关键字的值,它在这两种情况下都返回 null
So what I want is to look for the value of meta keyword only if below XPath exists.所以我想要的是仅当存在低于 XPath 时才查找 meta 关键字的值。
//html/head/meta[@name='keywords']/@content
if (keywordXPath.exists()){ // ----> how to do it in Groovy JSR223 Assertion?
if (keyword.equals("") || keyword == null) {
// to do
} else {
// to do
}
}
How can I check XPath present or not in Groovy JSR223 Assertion?如何在 Groovy JSR223 断言中检查 XPath 是否存在?
It sounds you're going into wrong direction.听起来你走错了方向。
However these methods assume your response is valid XML or XHTML , any inconsistency - and your code will fail但是,这些方法假定您的响应是有效的 XML 或 XHTML ,任何不一致 - 您的代码将失败
So I would rather use JMeter's XPath2 Extractor to store the "interesting" values from the response into JMeter Variables and then use vars
shorthand for JMeterVariables class instance to see whether the variable is defined or not like:因此,我宁愿使用JMeter 的 XPath2 Extractor将响应中的“有趣”值存储到JMeter 变量中,然后对JMeterVariables class 实例使用
vars
简写来查看变量是否已定义:
if (vars.get('variable from XPath2 Extractor`) != null) {
//your code here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.