2011-03-10 24 views
5

htmlunit kullanıyorum. "value" özelliğine sahip değilse, metin girdisi değerini nasıl ayarlayabilirim? htmlunit java değiştir giriş metni

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

Bunu denedim, ama yardım edin şey

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

!

+0

"Ama hiçbir şey" ne anlama geliyor? – skaffman

+0

Özellikle html metin girişine değer eklememiş olsanız bile 'değer' özniteliğini ayarlayabilmeniz gerekir. Karşılaştığınız hata nedir? – Nishan

cevap

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

intputBox.setValueAttribute("text"); 
+2

Kodunuzun bir açıklamasını ekleyebilir misiniz? – Ren