【发布时间】:2021-03-04 13:07:29
【问题描述】:
我在 Android 中有一个 Webview,我希望它在 google 中搜索我的关键字,然后单击一个名为 http://digikala.com/ 的网站并对其执行一些任务。
我在 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()
}
还有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);" +
"})()"
);
}
结果是什么都没有发生。没有错误,没有点击!
【问题讨论】:
标签: javascript android kotlin webview click