Android: run Javascript in WebView
Good afternoon, you need to automatically click on the button at the end of loading the page in WebView
. I do this, but the button is clicked from the WebView, but not programmatically.
What can be done in this situation?
Thanks.
public class RostelecomLoginActivity extends Activity {
WebView webView;
String url;
@SupressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_rostelecom_login);
Intent webIntent = getIntent();
final String url = webIntent.getStringExtra("url");
webView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSavePassword(true);
webSettings.setSaveFormData(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient() {
public void onPageLoad(WebView view, String url) {
}
public void onPageStarted() {
}
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:document.getElementById('mA').click()");
}
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
webView.loadUrl(url);
}
}
6
Author: Lex Hobbit, 2013-06-13
1 answers
It is not visible that WebSettings are applied to the WebView. I would still try
webView.getSettings().setJavaScriptEnabled(true);
1
Author: Станислав Земляков, 2017-06-15 12:44:22