2017-02-10 55 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 –