1

i am trying to set the value of the html form elements after loaded into webview.I tried to set using

org.w3c.dom.Document doc = webEngine.getDocument();
HTMLFormElement form = (HTMLFormElement) doc.getElementsByTagName("form").item(0);
NodeList nodes = form.getElementsByTagName("input");
nodes.item(1).setNodeValue("yadayada"); //this is where i am setting the value

but no success. can anybody help me out. here is my code.

org.w3c.dom.Document doc = webEngine.getDocument();                 
if (doc!=null && doc.getElementsByTagName("form").getLength() > 0) {
      HTMLFormElement form = (HTMLFormElement) doc.getElementsByTagName("form").item(0);
      String username = null;
      String password = null;
      NodeList nodes = form.getElementsByTagName("input");
      for (int i = 0; i < nodes.getLength(); i++) {
      if(nodes.item(i).hasAttributes()){
          NamedNodeMap attr = nodes.item(i).getAttributes();
          for (int j=0 ; j<attr.getLength();j++){
             Attr atribute = (Attr)attr.item(j);
             if(atribute.getValue().equals("password")){
             System.out.println("Password detected");
             nodes.item(i).setNodeValue("123456");
           }
         }
      }
   }
 }
2
  • Can you post a sample HTML file this is supposed to work with? (Better still, create a minimal reproducible example.) Commented Mar 24, 2017 at 19:04
  • thanks @James_D for your help. I got my problem solved. Commented Mar 24, 2017 at 19:39

1 Answer 1

1

i found the solution after surfing the web. The problem was i was using set node value but values of input tags are set using HTMLInputElement.This link was valuabe for me Performing an automated form post of login using webview for example

HTMLInputElement password = (HTMLInputElement) nodes.item(0).setValue("yadayada");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.