0

I've already tried the solution like this:

const element = // button address
 
const event = new MouseEvent("click", {
    bubbles: true,
    cancelable: true,
    view: window
});

//Or this
const event = new MouseEvent("click");

//Or this
const event = new Event("click", { bubbles: true });

element.dispatchEvent(event);

And other one like this:

elem.click()

both seems to not be able to trigger the click on the inline button, your help is appreciated thanks!

I tried the above solutions and I was trying to trigger a click on the inline button programmatically to automate few things, and keep in mind that's not my own bot

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

0

ok guys, got the answer. Just need to simulate a long key press. Below was the working solution, thank me later hehe:

function simulateLongPress() {
  const element = document.getElementById("myElement"); // Replace "myElement" with the actual ID of your target element

  // Create and dispatch a "mousedown" event
  const mousedownEvent = new MouseEvent("mousedown", {
    bubbles: true,
    cancelable: true,
    view: window
  });
  element.dispatchEvent(mousedownEvent);

  // Wait for a specific duration to simulate the long press
  const longPressDuration = 1000; // 1 second
  setTimeout(() => {
    // Create and dispatch a "mouseup" event
    const mouseupEvent = new MouseEvent("mouseup", {
      bubbles: true,
      cancelable: true,
      view: window
    });
    element.dispatchEvent(mouseupEvent);

    // Create and dispatch a "click" event
    const clickEvent = new MouseEvent("click", {
      bubbles: true,
      cancelable: true,
      view: window
    });
    element.dispatchEvent(clickEvent);
  }, longPressDuration);
}

// Call the function to simulate a long press
simulateLongPress();

actually no need for the timing, just the mousedown event does the work!