简体   繁体   中英

Android Studio WebView click on a loaded html page's element

I am loading a website in my app that contains an element I want to programmatically click (automate the click) as when this is clicked is time sensitive. I have the timing part down but need to trigger this element via an on screen click. I have read that performClick() "should" work but I have no way to verify if its actually clicking in the webview or not. The element in the html I need to trigger with a "touch" is called 'overlay'. Could someone provide me with a template that could do this?

You can use the below snippet to trigger at touch.

Video_Player.my_runnable = new Runnable()
                {
                    @Override
                    public void run()
                    {
                        view.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis() + 50,MotionEvent.ACTION_DOWN,300,300,0));
                        view.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis() + 50,MotionEvent.ACTION_UP,300,300,0));
                    }
                };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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