如何为HtmlUnit中没有value属性的文本字段提供值?下面

问题描述:

HTML元素是一种形式的一部分:如何为HtmlUnit中没有value属性的文本字段提供值?下面

<input id="code" type="text" name="code" placeholder="Enter code here" autocomplete="off"/> 

我想一个字符串传递给这个元素。我不知道如何传递没有值属性的字符串。

+0

你会与任何其他领域做同样的方式。 –

+0

你能举个例子吗? – cheyrico2

+0

http://htmlunit.sourceforge.net/gettingStarted.html#Submitting_a_form –

你可以尝试使用setText()方法将字符串传递给输入:

HtmlTextInput input = (HtmlTextInput) page.getElementById("code"); 
input.setText("your_text"); 

type()方法:

HtmlTextInput input = (HtmlTextInput) page.getElementById("code"); 
input.type("your_text");