【发布时间】:2017-08-31 15:48:09
【问题描述】:
根据我的标题,我希望在我的WebView 中检测到点击按钮并自动填写用户名密码字段。这是我所拥有的:
@Override
public void onPageFinished(final WebView view, String url) {
String user = "user";
String pwd = "password";
view.addJavascriptInterface(new Object() {
@JavascriptInterface
public void performClick() throws Exception {
Log.d("LOGIN::", "Clicked from on finished");
Toast.makeText(getApplicationContext(), "Login clicked", Toast.LENGTH_LONG).show();
String js = "javascript:document.getElementById('login')[0].value = '" + user+ "';document.getElementById('login')[1].value='" + pwd+ "';";
view.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
Log.d("form filled javascript", s); // Prints the string 'null' NOT Java null
}
})
}
}, "fill");
我能够检测到对按钮的点击,但无法填写表单。
【问题讨论】:
标签: android webview anonymous-inner-class