简体   繁体   English

以编程方式单击 Android WebView 中的元素

[英]Click programmatically on an element in Android WebView

I'm trying to perform a click on an element inside a website.我正在尝试单击网站内的元素。 The website is loaded in a WebView (Android) and the click I'm trying to perform is made using JS code.该网站加载在 WebView (Android) 中,我尝试执行的点击是使用 JS 代码进行的。 The problem is I'm getting:问题是我得到:

"uncaught typeerror cannot read property 'click' of null" “未捕获的类型错误无法读取 null 的属性 'click'”

The code I'm using in my WebViewClient class is:我在 WebViewClient 类中使用的代码是:

view?.loadUrl("javascript:(function doSomething() { document.getElementById('id').click(); }) ()")

*I tried executing this line after a timer and after the page is loaded. *我尝试在计时器和页面加载后执行此行。

试试这个

  webView.evaluateJavascript("javascript:(function doSomething() { document.getElementById('id').click(); }) ()", null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM