我想从Android的一个web视图填写Web表单。 我已经发现了这片code在这里:填写的WebView领域自动
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.
感谢您帮助
您应填写这些值的页面加载后。这是使用code的例子:
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+"';");
}
});
上一篇:图片URI来bytesarray图片、URI、bytesarray
下一篇:AppDomain.CurrentDomain.SetupInformation.PrivateBinPath为nullCurrentDomain、AppDomain、SetupInformation