WHITE PAPERS  |  PRICING  |  DOWNLOADS

 

username

password

 

 

 

 

 

 

 

 

 

 

  Desktop Edition Details  

 

  > Features  

  > Key Benefits  

  > Screenshots  

  > Standards Supported  

  > Pricing  

  > Download Now

 

 

  Developer Resources  

 

  > API Documentation  

  > Developers Guide  

  > Code Examples  

  > Updated Builds  

  > Technical Articles  

 

 

 

 

 

Jump to:

General WebRenderer Functions

  WebRenderer example code base.

 

Advanced WebRenderer functions

 

Application test examples

 

Deploying WebRenderer

WebRenderer DOM

  

  

 

Making use of the WebRenderer DOM to get FORM elements

 

 

 

Getting FORM Elements with the WebRenderer DOM

The WebRenderer DOM can be used to traverse through the structure of documents and find certain elements. This example displays navigating through the WebRenderer DOM and getting all FORM elements.

Example of getting Input type FORM Elements

try {
       IDocument doc = browser.getDocument();
       //Get the Forms in the Document
       IElementCollection forms = doc.getForms();
       System.out.println("There are " + forms.length() + " forms.");

       //Go through and find all the INPUTs for each form
       //and print thier name and value
       for (int i = 0; i < forms.length(); i++) {
                 System.out.println("<FORM " + i + ">");
                 IElement form = forms.item(i);
                 Vector inputs = new Vector();

                 //Call a function that recursivly goes through all
                 //children from an IElement and fills a Vector
                 //with children with the INPUT tag
                 getInputElementsForForm(form, inputs);

                 for (int j = 0; j < inputs.size(); j++) {
                           IElement input = (IElement) inputs.elementAt(j);
                           System.out.println( "INPUT: name:"+ input.getAttribute("name", 0) + "\t value:" + input.getValue());
                            if(input.getValue().indexOf("Google Search") != -1){
                                    googleSearchBtn = input;
                            } else if(input.getAttribute("name", 0).equals("q")){
                                    // Working on implementing/fixing setValue and setAttribute bug
                                    //System.out.println("Got the Q textfield");
                                    //input.setValue("Set within Java");
                                    //System.out.println("getAttribute: "+input.getAttribute("q", 0));
                            }
                 }
       }
} catch (Exception ex) {
       System.out.println("Exception caught: " + e);
}

///////

public void getInputElementsForForm(IElement at, Vector items) {
       //If the current element has the tagName INPUT, add it to the Vector
       if ((at.getTagName() != null) && (at.getTagName().equalsIgnoreCase("input"))) {
                 items.add(at);
       } else {
       //It's not an Input so call this function on all it's children
                 IElementCollection childs = at.getChildElements();
                 if (childs != null) {
                           for (int i = 0; i < childs.length(); i++) {
                                    getInputElementsForForm(childs.item(i), items);
                           }
                 }
       }

 

  top

 

 

 Sun, Sun Microsystems, and the Sun Logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries 

Privacy Policy  |   Disclaimer