I have a Webview in Android and i want it search my keyword in google and click a website which is http://digikala.com/ and do some task on it.
I tried following in kotlin:
findViewById<WebView>(R.id.web).settings.javaScriptEnabled = true
findViewById<WebView>(R.id.web).settings.loadsImagesAutomatically = true
findViewById<WebView>(R.id.web).settings.pluginState = WebSettings.PluginState.ON
findViewById<WebView>(R.id.web).webViewClient = MyBrowser()
findViewById<WebView>(R.id.web).loadUrl("https://www.google.com/search?q=$mykey")
btn.setOnClickListener{
btnPressed()
}
Also btnPressed()
fun btnPressed() {
findViewById<WebView>(R.id.web).loadUrl(
"javascript:(function(){" +
"l=document.getElementsByClassName('yuRUbf');" +
"e=document.createEvent('HTMLEvents');" +
"e.initEvent('click',true,true);" +
"l.dispatchEvent(e);" +
"})()"
);
}
The result is nothing happen. No Error and No Click!
Please try this snippet