At times you need to visit web sites, login, navigate through pages, select portions of HTML, click on links, check for the existence of a form, submit the form,.... and do all these things programmatically. So you need a programmable web browser that can execute and have a cup of tea while it will do the job.
Java SE API has the HTMLEditorKit that you can use to parse HTML pages. I have used it once. But it's very limited in capabilities. It's for parsing, but not to implement simple or complex navigation scenarios.
Given that httpunit.jar and the other jar file dependencies of httpunit are added to the class path, you can execute the above like this (after compilation):
See below to download this simple application as an Eclipse project with httpunit libraries packed inside.