Ok. It seems that this feature does not exist in HtmlUnit 2.1.13, therefore a feature request ticket was opened: https://sourceforge.net/p/htmlunit/feature-requests/215/
Anyway, I found a way in which a similar behavior can be achieved. Here it is:
public static HtmlFileInput insertFileInputWithValue(String name, String value,
String contentType, HtmlPage page, DomElement parent) {
// Necessary, otherwise HtmlUnit doesn't generate HtmlFileInput, but HtmlTextInput by default
AttributesImpl ai = new AttributesImpl();
ai.addAttribute(null, null, "type", null, "file");
ai.addAttribute(null, null, "name", null, name);
HtmlFileInput input = (HtmlFileInput) HTMLParser.getFactory("input")
.createElementNS(page, null, "input", ai, true);
input.setValueAttribute(value);
input.setContentType(contentType);
parent.appendChild(input);
return input;
}
These piece of code injects a new html input file in whatever parent you specify, a form most probably.
Even though HtmlUnit doesn't allow using <input type="file" multiple/>, the same behavior can be achieved by injecting more HtmlFileInput elements with the same name in your form, in which you set as values the files you want to upload.
I hope this helps.