2011-03-10 72 views
5

我使用htmlunit。 如何設置文本輸入的值,如果它沒有屬性「值」?htmlunit java更改輸入文本

<input type="text" onkeypress="test();" id="id" name="name" class="ttt"> 

我想這一點,但沒有

((HtmlTextInput) portfolios.getHtmlElementById("id")).setText("text"); 
    ((HtmlInput) portfolios.getHtmlElementById("id")).setTextContent("text"); 
    ((HtmlInput) portfolios.getHtmlElementById("id")).setAttribute("value", "text"); 

請幫幫忙!

+0

「但沒有什麼」是什麼意思? – skaffman 2011-03-10 14:51:52

+0

即使您沒有爲html文本輸入專門添加值,您也應該可以設置'value'屬性。你面臨的錯誤是什麼? – Nishan 2011-03-10 16:04:13

回答

7
HtmlInput intputBox = (HtmlInput)portfolios.getHtmlElementById('id'); 

intputBox.setValueAttribute("text"); 
+2

你可以添加你的代碼的解釋嗎? – Ren 2012-11-15 09:15:48