Search code examples
androidhtmlformsandroid-webview

Fill in web form from an app and submit


I have a webpage with a simple form with 3 input fields, Name, Email and Course and a submit button. Nothing fancy.

Upon developing an android app, I would like to know how I could fill in that web form from within my android app without using a webview to actually load the webpage.


Solution

  • I have used something like this in the past. However you will have to load a webview (though you dont need to show it.) then do something like below. Keep in mind that if the site changes the id down the road this approach will not work.

    webView.loadUrl("javascript:var 
        name=document.getElementById('nameInput').value='" yourNameValue "'");
    webView.loadUrl("javascript:document.getElementById('submit').click()");