Search code examples
javahtmlformsbrowserhtmlunit

Fill a html form without submit, just open the browser with fields filled. In JAVA


I'm developing a JAVA SWING application, and when i click on a button, and I want it to open a browser page with the HTML form fields fully filled(with the data that I want to pass from JAVA application), understood?

In this moment i'm using HtmlUnit library, but if you know something better, I'm open to sugestions!

This is what i have:

WebClient webClient = new WebClient();
HtmlPage page1 = webClient.getPage("http://www.google.com");
HtmlForm form = page1.getFormByName("search");
HtmlButton button = form.getButtonByName("submitSearch");
HtmlTextInput textField = form.getInputByName("searchTxtField");
textField.setValueAttribute("TEST VALUE");
HtmlPage page2 = button.click(); //final line

On the final line I submit the form, instead of that, I want it to open a web browser with the text:"TEXT VALUE" in "searchTxtField".

HELP ME, please...


Solution

  • HtmlUnit doesn't control any external web browser. It is a web browser (without any graphical UI).

    Use Selenium to control an external web browser.