Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:07:34+00:00 2026-06-06T23:07:34+00:00

HtmlUnit is an awesome Java library that allows you to programatically fill out and

  • 0

HtmlUnit is an awesome Java library that allows you to programatically fill out and submit web forms. I’m currently maintaining a pretty old system written in ASP, and instead of manually filling out this one web form on a monthly basis as I’m required, I’m trying to find a way to maybe automate the entire task because I keep forgetting about it. It’s a form for retrieving data gathered within a month. Here’s what I’ve coded so far:

WebClient client = new WebClient();
HtmlPage page = client.getPage("http://urlOfTheWebsite.com/search.aspx");

HtmlForm form = page.getFormByName("aspnetForm");       
HtmlSelect frMonth = form.getSelectByName("ctl00$cphContent$ddlStartMonth");
HtmlSelect frDay = form.getSelectByName("ctl00$cphContent$ddlStartDay");
HtmlSelect frYear = form.getSelectByName("ctl00$cphContent$ddlStartYear");
HtmlSelect toMonth = form.getSelectByName("ctl00$cphContent$ddlEndMonth");
HtmlSelect toDay = form.getSelectByName("ctl00$cphContent$ddlEndDay");
HtmlSelect toYear = form.getSelectByName("ctl00$cphContent$ddlEndYear");
HtmlCheckBoxInput games = form.getInputByName("ctl00$cphContent$chkListLottoGame$0");
HtmlSubmitInput submit = form.getInputByName("ctl00$cphContent$btnSearch");

frMonth.setSelectedAttribute("1", true);
frDay.setSelectedAttribute("1", true);
frYear.setSelectedAttribute("2012", true);
toMonth.setSelectedAttribute("1", true);
toDay.setSelectedAttribute("31", true);
toYear.setSelectedAttribute("2012", true);
games.setChecked(true);
submit.click();

After the click(), I’m supposed to wait for the very same web page to finish reloading because somewhere there is a table that displays the results of my search. Then, when the page is done loading, I need to download it as an HTML file (very much like “Save Page As…” in your favorite browser) because I will scrape out the data to compute their totals, and I’ve already done that using the Jsoup library.

My questions are:
1. How do I programatically wait for the web page to finish loading in HtmlUnit?
2. How do I programatically download the resulting web page as an HTML file?

I’ve looked into the HtmlUnit docs already and couldn’t find a class that’ll do what I need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:07:35+00:00Added an answer on June 6, 2026 at 11:07 pm

    How do I programatically download the resulting web page as an HTML file

    Try asXml(). Something like:

    page = submit.click();
    String htmlContent = page.asXml();
    File htmlFile = new File("C:/index.html");
    PrintWriter pw = new PrintWriter(htmlFile, true);
    pw.print(htmlContent);
    pw.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using HtmlUnit in Java to navigate to a web page. From that webpage
I'm currently using HtmlUnit to attempt to grab an href out of a page
What is the best library for a Java web scraper? I know the following
I'm dealing with data that has been sampled using Java HtmlUnit. The webpage used
I am currently playing around with different scraping techniques and found out, that it
Similar to htmlunit , but for use with C#. I've seen that you can
I'm trying to use HtmlUnit to test that my GWT website loads properly. Unfortunately,
I am having intermittent issues saving the response HTML in HtmlUnit. Caused by: java.io.IOException:
I have a page that comes back as an UnexpectedPage in HtmlUnit, the response
http://code.google.com/web/ajaxcrawling/docs/html-snapshot.html Does HtmlUnit work on AppEngine? If not, are there any other ways to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.