htmlunit java change input text

jim picture jim · Mar 10, 2011 · Viewed 10.4k times · Source

I use htmlunit. How i can set value of text input if it does not have an attribute 'value' ?

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

I tried this, but nothing

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

Please help!

Answer

Nosherwan Adil picture Nosherwan Adil · Aug 5, 2011
HtmlInput intputBox = (HtmlInput)portfolios.getHtmlElementById('id');

intputBox.setValueAttribute("text");