KirkPatrick 28 Junior Poster

This is sort of a follow up on my previous thread. I am looking into ways to click buttons, hyperlinks, or enter info into websites from a java program.

So I have taken a look into the following site:

http://www.informit.com/guides/content.aspx?g=java&seqNum=44

The page explains how to use the yahoo search. Here is the code:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

public class PostExample {
 public static void main( String[] args ) {
   String url = "http://search.yahoo.com/search";
   try {
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod( url );

	 // Configure the form parameters
	 method.addParameter( "p", "Java" );

	 // Execute the POST method
    int statusCode = client.executeMethod( method );
    if( statusCode != -1 ) {
      String contents = method.getResponseBodyAsString();
      method.releaseConnection();
      System.out.println( contents );
    }
   }
   catch( Exception e ) {
    e.printStackTrace();
   }
 }
}

A lot of the code isn't too hard to understand, but what I am wondering is how does it know to click the search button and not some other hyperlink on the page? I understand there is only one button on the page, but what if there are multiple ones? What if I want to click a specific hyperlink? What if the hyperlink that I'm wanting executes javascript?

Anyways I'm just looking for someone that might have some knowledge on the area and is willing to explain it a bit.