Reputation: 303
I am attempting to process a form in Java with HtmlUnit. It works fine until it tries to find and click the submit button.
Here is what the form looks like,
<form method="get" action="result.php">
<p>Text: <input type="text" name="text"/></p>
<p>Agree: <input type="checkbox" name="doYouAgree" value="agree" /></p>
<p><input type="submit" name="Submit" value="Submit"/></p>
</form>
I've searched around a tried many different methods for retrieving the element but it consistently returns HtmlTextInput rather than HtmlSubmitInput.
form.getInputByName("Submit").click();
I've also tried processing a form with every type of input and no matter the type it always returns HtmlTextInput.
Has anyone seen this issue or know how to correct it? I'm concerned that this is the reason why HtmlUnit is not submitting any forms.
Upvotes: 1
Views: 1452
Reputation: 436
You can submit a form with a base object, as DomElement.
DomElement button = page.getFirstByXPath("//input[@name='Submit']");
HtmlPage new_page = button.click(); // or you can use the old page
should work.
Upvotes: 1