JMeter XPath提取器SAXException [英] JMeter XPath Extractor SAXException

查看:128
本文介绍了JMeter XPath提取器SAXException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xpath提取器从响应数据中检索表单属性值.但是,此响应数据除其他数据外还包含字符串"C& I",这将导致以下SAXException

I am using xpath extractor to retrieve a form attribute value from the response data. However, this response data contains, among other data the String "C&I", and this is causing the following SAXException

jmeter.extractor.XPathExtractor:处理时发生SAXException (substring-after(//form[@id='headerForm']/@action,'/dashboard.xhtml?')) 对实体"I"的引用必须以;"结尾定界符.

jmeter.extractor.XPathExtractor: SAXException while processing (substring-after(//form[@id='headerForm']/@action,'/dashboard.xhtml?')) The reference to entity "I" must end with the ';' delimiter.

由于对此数据是从数据库中获取的,因此我无法对其进行任何控制.我尝试检查使用Tidy(宽容解析器)"选项.这将导致以下警告/错误

I do not have any control over this data since it is being obtained from the database. I tried checking the "Use Tidy(tolerant parser)" option. That results in the following warning/error

错误-jmeter.util.XPathUtil:TidyException:第35行第31列- 警告:修剪空的< div>

ERROR - jmeter.util.XPathUtil: TidyException: line 35 column 31 - Warning: trimming empty <div>

响应的第35行如下:


`<div style="clear: both;"></div>`

提取该属性值对于我的进一步处理至关重要.

Extracting that attribute value is essential for further processing for me.

推荐答案

对于所有可以解决的问题,它可能都是快速而肮脏的,但是对于单个问题总是有更多解决方案.

As for everything there is solution, it might be quick and dirty but there is always more solutions to a single problem.

我建议使用 jsoup 为您(而不是xpath提取器)进行HTML解析.我假设您正在尝试提取特定表单的action属性.

I recommend using jsoup to do the parsing of HTML for you instead of xpath extractor. I'm assuming you're trying to extract the particular forms' action attribute.

步骤1->将jsoup-1.6.3.jar或任何其他版本添加到您的JMETER_HOME\lib

Step 1 -> Add jsoup-1.6.3.jar or any other version to your JMETER_HOME\lib

第2步->将BeanShell PostProcessor添加到Sampler HTTP或任何其他

Step 2 -> Add a BeanShell PostProcessor to your Sampler HTTP or any other

步骤3->在脚本"大框中粘贴以下代码:

Step 3 -> In a Script big box paste this code :

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

String html = prev.getResponseDataAsString(); // get response from your sampler
Document doc = Jsoup.parse(html);
String formAction = doc.select("#headerForm").attr("action");
vars.put("action", formAction);

HTML选择器基于jquery.因此它可以做的非常漂亮和整洁.无论如何,您应该具有${action}变量以在测试中进一步使用.

HTML selectors are jquery based. So it can do pretty nice and neat things. Anyway you should have ${action} variable to use further in your tests.

更新

所以您不会与我创建的称为Html Extractor的jMeter后处理器的代码纠缠不清,这里是github url:

So you don't get tangled with the code I've created jMeter post processor called Html Extractor here is the github url :

https://github.com/c0mrade/Html-Extractor

这篇关于JMeter XPath提取器SAXException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆