0

Can anyone point me to a current example of how to use HTMLUnit to interact with a webpage (submit a form, click, etc) along with the current jars that work with the example? I donwloaded all the jars on the htmlunit page and all its dependent jars, and I keep getting NoSuchMethod errors, so I'm guessing I have mismatched jars.

user1154644
  • 4,491
  • 16
  • 59
  • 102

2 Answers2

0

Hi if you're having issues to set up HtmlUnit this answer might help How to setup HtmlUnit in an Eclipse project?

Regarding form submission and clicking, this is the example taken from the HtmlUnit documenation itself:

public void submittingForm() throws Exception {
    final WebClient webClient = new WebClient();

    // Get the first page
    final HtmlPage page1 = webClient.getPage("http://some_url");

    // Get the form that we are dealing with and within that form, 
    // find the submit button and the field that we want to change.
    HtmlForm form = page1.getFormByName("myform");

    HtmlSubmitInput button = form.getInputByName("submitbutton");
    HtmlTextInput textField = form.getInputByName("userid");

    // Change the value of the text field
    textField.setValueAttribute("root");

    // Now submit the form by clicking the button and get back the second page.
    final HtmlPage page2 = button.click();

    webClient.closeAllWindows();
}
Community
  • 1
  • 1
Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
0

HTMLUnit is integrated in Selenium WebDriver. http://www.seleniumhq.org/projects/webdriver/

the best advice that I can give you is, since you are working with Java, make it a Maven Project and add the dependencies for selenium.webdriver. Building the project as Maven avoids having common mistakes like saving the jars in a wrong directory or forgetting 1 jar