0

I am trying to use HtmlUnit to fill a form which puts some conditions on its inputs (for example the value of one input has to be at least 3 characters long). I use HtmlInput's setValueAttribute method to fill the form's, but when it clicks on the submit button the website shows a error message saying that the given value is shorter than 3 characters when it actually is not. It seems that when the value is set through HtmlUnit the website fails to recognize the length of the given value. Is there any way to work around this?

Here is the code I use:

HtmlInput intputBoxName = (HtmlInput) page.getFirstByXPath("//input[@id='usernamePart']");
intputBoxName.setValueAttribute("value");

I have also found that if i use inputBoxName.click() before setting the value the value is not set at all.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
XaitormanX
  • 891
  • 1
  • 11
  • 22

1 Answers1

2

You should use inputBoxName.type("value") instead, since setValueAttribute doesn't trigger JavaScript handles.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56