0

If I have a WebView such as below

    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("http://google.com");

Is there anyway to programmatically fill in the search text box? The text box has the name of q

Arya
  • 7,765
  • 24
  • 86
  • 160

1 Answers1

0

I believe you can programmatically get the WebView to run JavaScript. You can use that to execute/query the DOM. Try something like this:

webView.loadUrl("javascript:document.getElementByName('q').value = '" + queryHere + "';");

Just replace queryHere with a variable of your choice. You can similarly use JavaScript to then trigger form submits and other actions you might find useful.

Reference: https://stackoverflow.com/a/7961598/394933

Brian
  • 7,777
  • 15
  • 64
  • 104