Fill fields in webview automatically Fill fields in webview automatically android android

Fill fields in webview automatically


Thanks all for your answer, it helped me, but didn't work.

It was allways opening a white page until i found this :

https://stackoverflow.com/a/25606090/3204928

So here complete solution, mixing all infos found here and there :

1) first of all you have to enable DOM storage, if you don't do that, .GetElementByXXX will return nothing (you have to do it before loading the page)

myWebView.getSettings().setDomStorageEnabled(true);

2)Your last Javascript call on GetElementByXXX MUST store the result in a variable

Exemple 1 :

_webview.loadUrl("javascript:var uselessvar =document.getElementById('passwordfield').value='"+password+"';");

here only one call (only one semi-colon) so we immediatly store the result in 'uselessvar'

Example 2 : see user802467 answer

here there is 3 calls (one for login field, one for password field, one to submit button), only the last call need to be store, it's done in 'frms'

Javascript programmers should easily explain this behaviour...

hope this will help


You don't need to use "java commands"... but instead JavaScript... for instance:

String username = "cristian";webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");

So basically, what you have to do is a big string of JavaScript code that will get those fields and put values on them; also, you can enable/disable the submit button from JavaScript.


This worked for me to fill form values and submitting the form:

webView.loadUrl("javascript: {" +            "document.getElementById('username').value = '"+uname +"';" +            "document.getElementById('password').value = '"+password+"';" +            "var frms = document.getElementsByName('loginForm');" +            "frms[0].submit(); };");