fill form programmatically in Android Webview - JavaScript

后端 未结 4 921
灰色年华
灰色年华 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:12

    This is untested, but I see two things wrong here:

    1. You should call setWebViewClient with your WebViewClient implementation before you call loadUrl. However, loadUrl is asynchronous, so it probably would not make a difference, but this is worth a try I think.

    2. You are not calling super.onPageFinished(view, url); in onPageFinshed. You should add this call.

    EDIT 2:

    I finally took a look at the actual page you are working with. The problem is that the page loads content in a different frame, so you actually have to make the getElementsByName call on a different document. The frame in which both of the inputs you want are located has the name mainFrame in your page. So, you should write the javascript like this and load that into the WebView as you have done above:

    window.frames["mainFrame"].document.
                     getElementsByName('p_codigo_c')[0].value = "user";
    window.frames["mainFrame"].document.
                     getElementsByName('p_clave_c')[0].value = "password";
    

提交回复
热议问题