【问题标题】:Detect button clicked event and fill form in an android webview检测按钮单击事件并在android webview中填写表单
【发布时间】: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


    【解决方案1】:

    使用从 Android 到 JavaScript 的 JavaScript 接口,check documentation。

    【讨论】:

    • 这正是我正在使用的,查看我上面的代码 sn-p。
    猜你喜欢
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2020-12-03
    • 1970-01-01
    相关资源
    最近更新 更多