Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  137] [ 6]  / answers: 1 / hits: 20262  / 12 Years ago, tue, april 17, 2012, 12:00:00

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


More From » android

 Answers
14

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+';);
}
});

[#86193] Monday, April 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
masonm

Total Points: 167
Total Questions: 87
Total Answers: 103

Location: Rwanda
Member since Wed, Jun 8, 2022
2 Years ago
masonm questions
;