function click(cleanTableId) {
console.log("
const allElements = document.querySelectorAll("div[data-observer-id]");
const allMatches = [];
allElements.forEach((container) => {
const observerId = container.getAttribute("data-observer-id");
const baseId = observerId.replace(/-P.*/, "");
< /code>
Все элементы в iframe собираются в переменную и начинают сравниваться с CleanTableId < /p>
if (baseId === cleanTableId) {
console.log(`
allMatches.push(observerId);
const img = container.querySelector("img");
const target = img || container;
< /code>
Элемент «IMG» добавляется в соответствующий элемент, а метод прокрутки применяется и заполняет нажмите на элемент < /p>
container.scrollIntoView({ behavior: "smooth", block: "center" });
target.click();
const isVisible = target.offsetParent !== null && !target.disabled;
< /code>
Состояние создается для определения элемента в визуальной части, и щелчок происходит с помощью SetInterval < /p>
if (isVisible) {
console.log("
setTimeout(() => {
let attempts = 0;
const maxAttempts = 20;
const tryClick = setInterval(() => {
container.scrollIntoView({ behavior: "smooth", block: "center" });
target.click();
attempts++;
console.log("
if (attempts >= maxAttempts) {
console.warn("
clearInterval(tryClick);
}
}, 100);
}, 700);
}
}
});
console.log("
}
< /code>
Это консоль, когда элемент не находится в визуальной части < /p>
iframe-script.js:36
iframe-script.js:48
iframe-script.js:68
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:58
iframe-script.js:60
< /code>
Это консоль, когда элемент находится в визуальной части < /p>
iframe-script.js:36
iframe-script.js:48
iframe-script.js:68
Подробнее здесь: https://stackoverflow.com/questions/795 ... in-iframev
Мобильная версия