Google Answers Logo
View Question
 
Q: Using Java to fill out forms on web pages ( No Answer,   1 Comment )
Question  
Subject: Using Java to fill out forms on web pages
Category: Computers > Programming
Asked by: amirehsans-ga
List Price: $12.00
Posted: 04 Nov 2003 21:05 PST
Expires: 11 Nov 2003 14:40 PST
Question ID: 272743
Hi. I was wondering if you could give me a simple piece of Java code
that could fill out an online form for me. The whole idea is, let's
say there are 5 fields on a page (not my own, just on the net) and I
know what I want to put in them, but I want my java code to do it for
me. How can this be done?

Let's say I don't want it to be "that" intelligent.  So for the first
time, I go and look at the HTML code of the page and pull out the name
of all the fields to be filled or check boxes to be checked, or
*BUTTONS to be pushed*. So I know the name of the components.  Now can
I tell my program to go to a webpage and "click" on the button labeled
blah, and put "blah" into the text field called blah2, etc?

I would really appreciate your help.

Request for Question Clarification by wengland-ga on 06 Nov 2003 14:05 PST
Do you need the Java code to interact with the browser, so that
client-side scripting (Javascript or VBScript) will run?

Or do you simply need the Java code to submit an HTTP POST request to
the server with the appropriate values for the form fields?

Clarification of Question by amirehsans-ga on 06 Nov 2003 18:33 PST
I'm not sure if I quite get it, but I guess the end result is more
important to me.  So I "guess" your HTTP POST idea would work.

Let me clarify myself: Let's say there is a form on Reader's Digest's
website that you can submit your jokes to.  Let's also say that I'm
too lazy to do the following and I want my Java program to do it for
me:

1. go to the specific webpage, 
2. punch in my username in text field "userT" (I know from their HTML
code before hand)
3. punch in my password in text field "passT" (I know from their HTML code...)
4. Click on the button "submit" (I know from their HTML code ...)
5. Wait for a while (let's say 60 sec's so the other webpage is definitely loaded)
6. Put my joke in the "jokeTA" text area.
7. Click on "submit" button
8. Logout by *clicking* on a link.

Now I know I've added the new features of "clicking on a link". Please
tell me if this "clicking" can simply be done by connecting to the URL
represented by "logout" or not.

Please note that the username, password, and all link addresses and
field names are available to the program.

Also note that I have increased the payment for this question from $8
to $12. (for a functioning code)

Clarification of Question by amirehsans-ga on 11 Nov 2003 03:27 PST
** IMPORTANT **

I'm not asking for a full piece of code.  All I'm asking for is bits
and pieces of code, or some ideas on which classes to use to interact
with [perhaps] the browser.

But if you know such functionality does NOT exist in java, then please
do me a favor and tell me as a short "comment". In your comment,
please include any other web programming languages that would handle
this functionality.

Your help will be truly appreciated!

Clarification of Question by amirehsans-ga on 11 Nov 2003 14:39 PST
Hi wengland-ga. Just wanted to say thanks thanks thanks for your
comment. Your response was very helpful.  You're fantastic!
Answer  
There is no answer at this time.

Comments  
Subject: Re: Using Java to fill out forms on web pages
From: wengland-ga on 11 Nov 2003 09:05 PST
 
Greetings!

Assuming you really are wanting to submit forms to the Readers Digest
website, they use quite a bit of client side scripting (Javascript)
for form validation and submission.  This would preclude simply
creating a HTTP POST request with the values in it.

You'd need to disassemble what they do with the Javascript and either
mimic the functionality, or automate the submission with the web
browser.

Java does not have a way to control Windows applications, such as
pasting text in a box, or clicking on an image.

However, you can do this with either Visual Basic, or WinBatch.  I
know very little about those applications, so I leave it to other
researchers to flesh this out.

The general idea with Visual Basic would be to create your own
non-visual webbroswer using the IE components to handle the page
render and Javascript.  VB can be used to read in your joke
submissions from a database or text file, and populate the form.

With WinBatch, it acutally automates the 'tab' and 'enter' keys you'd
hit while navigating the page.  I assume it would also have a
mechanism to open text files , copy data, and paste it into the forms
on the page.

Good luck on your quest!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy