Reputation: 101
The following unit test fails:
@Test
public void test() throws Exception {
String html = "<html><form id=\"myform\"></form></html>";
Document document = Jsoup.parse(html);
Element inputElement = document.createElement("input");
inputElement.attr("name", "any_name");
inputElement.attr("value", "any_value");
Element formElement = document.getElementById("myform");
formElement = formElement.appendChild(inputElement);
List<Connection.KeyVal> formData = ((FormElement)formElement).formData();
Assert.assrt(1 == formData.size());
}
Questions:
Upvotes: 0
Views: 271
Reputation: 4266
You have to add the input
element to the form!
Look at the documentation of addElement​(Element element)
:
Add a form control element to this form.
So, in your case, you have to add the following line to your code before the assertion:
((FormElement) formElement).addElement(inputElement);
Upvotes: 0