Дискусии » Заявки за създаване
How to select a random generated ID?
const idRegex = /[a-z0-9]{64}/;
const buttons = document.querySelectorAll('button');
for (const btn of buttons) {
if (idRegex.test(btn.id)) {
btn.click();
break;
}
}
This should click on first closest button from querySelectorAll('button')
with id such like that
const idRegex = /[a-z0-9]{64}/; const buttons = document.querySelectorAll('button'); for (const btn of buttons) { if (idRegex.test(btn.id)) { btn.click(); break; } }
Awesome! It works! Thank you very much!
Is it possible to add some wait time before the click somewhere?
window.addEventListener('load', function() {
const idRegex = /[a-z0-9]{64}/;
const buttons = document.querySelectorAll('button');
for (const btn of buttons) {
if (idRegex.test(btn.id)) {
btn.click();
break;
}
}
(function (){
document.querySelector('button').click();
})();
}, false);
window.addEventListener('load', function() {
const someWaitTime = 1600;
const idRegex = /[a-z0-9]{64}/;
const buttons = document.querySelectorAll('button');
for (const btn of buttons) {
if (idRegex.test(btn.id)) {
setTimeout(() => btn.click(), someWaitTime);
break;
}
}
});
Thank you very much!
I want to click on a button automatically, but the button has a random generated ID each time like 081ab90900313289a80c11ce8af2b7ccfcbb0ecef313807f2fa8e0b229cb2fc1. I know there has to be an elegant way how to achieve that, but didn't find it myself yet. I want to use it like this:
(function (){document.querySelector('button[id="randomID"]').click();
Thank you!