Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto click on WebView

How can I perform click on WebView from java code? Is it possible to click on a specified location (x,y)?

WebView.performClick()

doesn't work!

like image 432
Ashish Anand Avatar asked Nov 13 '22 19:11

Ashish Anand


1 Answers

You can do this by injecting javascript to your webview using loadUrl():

mWebView.loadUrl("javascript:<your javascript here>");

This example code will perform a click on the element with id 'button_submit':

mWebView = new WebView(context);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("javascript:getElementById('button_submit').click();");
like image 56
J.G.Sebring Avatar answered Dec 12 '22 02:12

J.G.Sebring