jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Automating HTML form input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Automating HTML form input" Watch "Automating HTML form input" New topic
Author

Automating HTML form input

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
Hi,

I'm using a web site that has a form with an input field and a submit button. I have many values that I would like to input to this site using this form and find entering them one at a time very tedious.
I would like to automate the input to the HTML form as much as possible. So far I have three programming solutions:

1) Proxy server - this program intercepts the incoming html and changes it to preload the next value to be submitted. After the page has loaded in the browser with the field in the form filled in, I press the submit button and wait for the next preloaded page to arrive. I continue pressing submit after each preload until all the data has been submitted. I have this code mostly working.

2) Robot inputter - After loading the form into the browser, this program would be initialized to know where the input field is and where the submit button is. On pressing its DoIt button, it would get the next line to be submitted, write it to the input field and press the form's submit button. I would wait until the form is loaded then press the Robot program's DoIt button to do it again. This would require the user to watch and wait until the HTML page has been loaded and is ready to receive input. Is the Java Robot class capable of doing this?

3) Automatic "browser" - This program would do all the browser functions, fill in the form and do the submit without any user interventions. The HTML engine in this program would need to be able to handle JavaScript etc. Is this possible?

Are there other ways of doing this?


Thanks,

Norm
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Can you take the browser out of the picture entirely? Using URL and HttpURLConnection you can post anything you like with just Java.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
I suggest the HttpClient library for imitating a browser instead of Java Robot. Much easier than programming from scratch with HttpURLConnection, particularly if the service you have to talk to uses cookies to track users.

HttpClient - an Apache Software Foundation open source toolkit is well supported.

What is the source of data to fill in the form?

Bill
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
Thanks for the responses.

The HTML page I'm working with has several forms on it, maps and a good bit of Javascript. It would be a very difficult task to correctly format the data for the POST action generated by pressing one of the submit buttons. I think that a browser is needed to do that. I was hoping that the HTMLDocument would do some of the work, but I haven't found any examples.

Norm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automating HTML form input