I tried applying this using ChatGPT, but it didn't work for me. Can you tell me where to put this code to make my code work?
// Функция для эмуляции нажатия мыши внутри элемента <canvas data-sentry-element="Stage"> function simulateMouseClickInCanvas() { const canvas = document.querySelector('canvas[data-sentry-element="Stage"]'); if (!canvas) { console.error("Элемент <canvas> не найден."); return; } const rect = canvas.getBoundingClientRect(); // Выбираем случайные координаты внутри элемента <canvas> const randomX = Math.random() * rect.width + rect.left; const randomY = Math.random() * rect.height + rect.top; // Создаём события мыши const mouseDownEvent = new MouseEvent("mousedown", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); const mouseUpEvent = new MouseEvent("mouseup", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); const clickEvent = new MouseEvent("click", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); // Эмулируем события canvas.dispatchEvent(mouseDownEvent); canvas.dispatchEvent(mouseUpEvent); canvas.dispatchEvent(clickEvent); } // Функция для выполнения кликов с рандомной задержкой function performRandomClicksInCanvas(maxClicks) { let clicksCount = 0; function clickWithRandomDelay() { if (clicksCount >= maxClicks) { console.log("Все клики выполнены"); return; } const delay = Math.random() * (2000 - 100) + 100; // Рандомная задержка от 0.1 до 2 секунд setTimeout(() => { simulateMouseClickInCanvas(); clicksCount++; console.log(`Клик ${clicksCount} выполнен (задержка: ${Math.round(delay)} мс)`); clickWithRandomDelay(); // Рекурсивный вызов для следующего клика }, delay); } clickWithRandomDelay(); } // Запуск выполнения 10 кликов performRandomClicksInCanvas(10);Error: Type Text not working with selector "at" with variables
-
BAS version: 24.1.1
OS: Windows 10 (21H1)I want to use "Type Text" by coordinates from variables.
On the website have a button with select options and in the same line an input field (gm@il reg form, phone number input).
First, I use "Get Coordinates" to get coordinates of the countries button, then I create new X-Y variables, increase the X with 150 and increase the Y with 20. The new X-Y variables will point into phone number input field (I already checked, the new X-Y variables pointing into the right place).
The issue:
When I want to use the new X-Y variables in the "Type Text" (of course with selector "at") then the pointer moving in the center of the country button. But if I set the right integers into "Type Text" selector "at", then it's working perfectly!Please help, what can be wrong.
Thank you. -
@jasjas said in Error: Type Text not working with selector "at" with variables:
BAS version: 24.1.1
OS: Windows 10 (21H1)I want to use "Type Text" by coordinates from variables.
On the website have a button with select options and in the same line an input field (gm@il reg form, phone number input).
First, I use "Get Coordinates" to get coordinates of the countries button, then I create new X-Y variables, increase the X with 150 and increase the Y with 20. The new X-Y variables will point into phone number input field (I already checked, the new X-Y variables pointing into the right place).
The issue:
When I want to use the new X-Y variables in the "Type Text" (of course with selector "at") then the pointer moving in the center of the country button. But if I set the right integers into "Type Text" selector "at", then it's working perfectly!Please help, what can be wrong.
Thank you.Have you read the description of the at selector? This selector determines the element by coordinates, and then the algorithm finds the approximate coordinates in the middle of the element and makes a click.
-
@Fox Thank you for the extreme fast reply!
Sure, I already read. I give coordinates but from variables. There is an "@" sign which is allow to insert variables too into selector's input field.
....or I misunderstand something, please?
Here is a screenshot, what I mean:
https://i.ibb.co/W6y4bYY/Screenshot-1.pngThank you
-
@jasjas said in Error: Type Text not working with selector "at" with variables:
@Fox Thank you for the extreme fast reply!
Sure, I already read. I give coordinates but from variables. There is an "@" sign which is allow to insert variables too into selector's input field.
....or I misunderstand something, please?
Here is a screenshot, what I mean:
https://i.ibb.co/W6y4bYY/Screenshot-1.pngThank you
I explain again, you specify the coordinates not for the click (data entry), but the coordinates inside the element. The algorithm uses these coordinates to find the element and selects the coordinates for the click itself, guided by the size of the element.
To make a click in the exact coordinates, use the "Click" action, and then the "Type" action from the browser module

