Issue
I'm trying to fill Webforms from a Webview in Android. I've already found this piece of code here: Fill fields in webview automatically
String username = "cristian";
webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");
Unfortunatly I dont understand where I have to open the page I want to fill in.
setContentView(R.layout.web);
final WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
String user="u";
String pwd="p";
mWebView.loadUrl("javascript:document.getElementById('username').value = '"+user+"';document.getElementById('password').value='"+pwd+"';");
When I try it this way, the site gets displayed but without any values in the forms.
Thanks in advance for helping
Solution
You should fill the values after the page has been loaded. This is an example using your code:
mWebView.loadUrl(url);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String user="u";
String pwd="p";
view.loadUrl("javascript:document.getElementById('username').value = '"+user+"';document.getElementById('password').value='"+pwd+"';");
}
});
Answered By - gnpaolo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.