I have the code to click on an element
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
const delayTime = 1000;
const divSelector = 'div.w-full.bg-background-lighten2.rounded-lg.border.border-transparent.hover\\:border-white.active\\:border-info-lighten2.relative.transition-all.duration-200.ease-in-out';
const imgSelector = 'img[src="https://b.galxestatic.com/new-web-prd/s/276af4b/_next/static/assets/image/credential-types/icon-twitter.png"]'; // Указание src для картинки
const clickElementByIndex = async (index) => {
const elements = document.querySelectorAll(divSelector);
if (index >= 0 && index < elements.length) {
const element = elements[index]; // Получаем элемент с заданным индексом
const imgs = element.querySelectorAll(imgSelector); // Ищем img с нужным src
if (imgs.length > 0) {
try {
const img = imgs[0]; // Если несколько изображений, кликаем по первому
const event = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
img.dispatchEvent(event); // Кликаем по изображению
await delay(delayTime); // Задержка между кликами
} catch (error) {
console.error('Ошибка при обработке элемента:', error);
}
} else {
console.log('Изображение не найдено в элементе с индексом', index);
}
} else {
console.log('Неверный индекс', index);
}
};
// Пример вызова с индексом элемента (например, индекс 2)
clickElementByIndex(2);
In the developer console it works correctly, but in BAS click occurs page after click does not open