I am able to simulate tap events on typical android views (textbox, button, etc.) using MotionEvent.obtain, like this:
int meta_state = 0;
MotionEvent motionEvent = MotionEvent.obtain(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN,
x,
y,
meta_state
);
motionEvent.recycle();
view_tapped.dispatchTouchEvent(motionEvent);
view_tapped is a reference to the view I want to sent the event to. However, when I call dispatchTouchEvent on a webview, it doesn't seem to tap any element inside.
I've also put an onTouchListener inside the webview, and then dumped all the information related to the motionevent when the view is actually tapped by a finger, and then created a new motionevent with all of the same information and dispatched it to the webview, and it isn't tapping the screen. The onTouchListener is still fired, but the element on the screen isn't tapped.
I also tried doing it with Javascript, by trying to figure out which element was at the specific coordinate and then firing the click event by injecting javascript, but no luck either.
Any ideas as to what I'm doing wrong?