2017-02-10 50 views
1

我试图让JMeter的在下面的XPath读预填充表单输入值:/html/body/div[1]/div[3]/div[2]/form/table/tbody/tr[2]/td/div[1]/input/@valueJMeter的XPath的提取对HTML5内容

因为我只得到错误的结果,我调查并启用整洁(宽容解析器),以及冗长(不安静;报告错误),我发现这一点:

ERROR - jmeter.util.XPathUtil: TidyException: line 65 column 9 - Error: <nav> is not recognized! 
line 95 column 11 - Error: <nav> is not recognized! 
InputStream: Doctype given is "" 
InputStream: Document content looks like HTML 4.01 Transitional 
85 warnings, 2 errors were found! 
This document has errors that must be fixed before 
using HTML Tidy to generate a tidied up version. 

由于我们是在2017年,该文件当然是用HTML5编写和<nav>的是一个完全有效的标签。然而泰迪却没有认识到它。我使用JMeter 3.1 r1770033运行最新的Arch Linux系统。

如何在JMeter中为HTML5网站使用XPath?

+0

显示'HTML'为目标'input'字段 – Andersson

+0

'<输入的ID = “title_de” class =“string optional”value =“那么这是一个强大的价值。” name =“my_element [title_de]”type =“text”>' – Kalsan

+0

您是否尝试使用https://github.com/htacg/tidy-html5而不是当前的'Tidy'版本? – Andersson

回答

1

使用Xpath Extractor

//input[@id='title_de']/@value 

截图引用: Xpath的提取配置: enter image description here

查看结果树: enter image description here


使用Regular Expression Extractor

input id="title_de" class="string optional" value="(.*?)" 

截图引用: enter image description here

查看结果树(高亮显示的所捕获的值): enter image description here

+1

非常感谢,正则表达式提取器是一个可行的选择。 XPath Extractor将不起作用,因为文档中的其他位置有'

+0

还有一件事:如果字段名称包含像'['这样的符号,那么这些符号必须被转义才能正常工作:'\ [' – Kalsan

+0

是的。 '[]'用于'字符类'。所以使用'\'转义。完整列表在这里http://jmeter.apache.org/usermanual/regular_expressions.html –