Fill fields in webview automatically

前端 未结 6 1724
小蘑菇
小蘑菇 2020-11-27 04:26

I have seen this question floating around the internet, but I haven\'t found a working solution yet. Basically, I want to load my app and press a button; the button action w

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 05:01

    Thanks all for your answer, it helped me, but didn't work.

    It was allways opening a white page until i found this :

    https://stackoverflow.com/a/25606090/3204928

    So here complete solution, mixing all infos found here and there :

    1) first of all you have to enable DOM storage, if you don't do that, .GetElementByXXX will return nothing (you have to do it before loading the page)

    myWebView.getSettings().setDomStorageEnabled(true);
    

    2)Your last Javascript call on GetElementByXXX MUST store the result in a variable

    Exemple 1 :

    _webview.loadUrl("javascript:var uselessvar =document.getElementById('passwordfield').value='"+password+"';");
    

    here only one call (only one semi-colon) so we immediatly store the result in 'uselessvar'

    Example 2 : see user802467 answer

    here there is 3 calls (one for login field, one for password field, one to submit button), only the last call need to be store, it's done in 'frms'

    Javascript programmers should easily explain this behaviour...

    hope this will help

提交回复
热议问题