0

I'm loading a website for searching ads into Webview in Java Android. I can pre-fill Searchkeyword field but I can't seem to trigger the Search icon click() to submit the search.

I use the same code on other websites and it works fine. I can trigger the click() event.

This is the website that i'm loading into WebView http://www.kijiji.ca/

What it suppose to do is fill in the Search word and then select the Search icon to query the search show the result.

            String searchKeyword = "cars";

            final String js = "javascript:" +
                    "document.getElementById('SearchKeyword').value = '" + searchKeyword + "';"  +
                    "document.getElementById('header-button-submit').click()";

            if (Build.VERSION.SDK_INT >= 19) {
                view.evaluateJavascript(js, new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String s) {
                        String result = s;

                    }
                });
            } else {
                view.loadUrl(js);
            }

Am I getting the correct id from the html doc "header-button-submit"?

Smiley
  • 31
  • 1
  • 4
  • 1
    Possible duplicate [programmatic click in Android WebView](http://stackoverflow.com/questions/16709963/programmatic-click-in-android-webview) – Fady Saad Apr 28 '17 at 04:48

1 Answers1

0

In the website, button does not contain id. So this document.getElementById('header-button-submit').click()will not work. Use getElementsByClassName or getElementsByName.

Example : document.getElementsByClassName('searchSubmit-3685231415 searchSubmit__on-407610085').click() or document.getElementsByName('SearchSubmit').click()

Sallu
  • 141
  • 3
  • 17