fill form programmatically in Android Webview - JavaScript

后端 未结 4 920
灰色年华
灰色年华 2021-01-15 07:33

I\'m trying to automatically fill a form from the website of my school. I\'ve seen some ways to do with javascrip.

Here is my code:

@Override
prote         


        
4条回答
  •  花落未央
    2021-01-15 08:11

    this works for me for API version greater than 18

     mWebView = findViewById(R.id.web_view);   
            String url = "https://duckduckgo.com";
    
            mWebView.loadUrl(url);  
            mWebView.getSettings().setJavaScriptEnabled(true);
    
            final String js = "javascript:document.getElementById('search_form_input_homepage').value='android';" +
                    "document.getElementById('search_button_homepage').click()";
    
            mWebView.setWebViewClient(new WebViewClient(){
    
                public void onPageFinished(WebView view, String url){
                    if(Build.VERSION.SDK_INT >= 19){
                        view.evaluateJavascript(js, new ValueCallback() {
                            @Override
                            public void onReceiveValue(String s) {
                            }
                        });
                    }
                }
            });
    

    here important is view.evaluateJavascript

提交回复
热议问题