this is my onBackPressed:
@Override
public void onBackPressed() {
if (Config.EXIT_APP_BY_BACK_BUTTON_ALWAYS) {
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("javascript:(function(){"+
"l=document.getElementById('sdf_1422');"+
"e=document.createEvent('HTMLEvents');"+
"e.initEvent('click',true,true);"+
"l.dispatchEvent(e);"+
"})()");
}}
This works very well but the problem is that my page contains a lot of div's of sdf_1422, sdf_1423, sdf_1424, and so on. Can you help my to get all the sdf_, and click them.
You can get all the elements you are looking for with document.querySelectorAll("div[id^=sdf_]") This is looking for all divs with id starting with sdf_ . This function returns a nodelist.
You can iterate a nodelist and add an event to every node:
let list = document.querySelectorAll("div[id^=sdf_]");
list.forEach(element => { element.addEventListener('click', () => {}) })