Skip to content

Instantly share code, notes, and snippets.

@BoQsc
Last active August 25, 2022 04:57
Show Gist options
  • Save BoQsc/a5e9f60de3c8f26dd696678b2d8314eb to your computer and use it in GitHub Desktop.
Save BoQsc/a5e9f60de3c8f26dd696678b2d8314eb to your computer and use it in GitHub Desktop.
How to find the clickable elements inside elements for a JavaScript Mouse Dispatch (A simulation of a click)
tutorLocateClickableElement.mp4

Examples of simulating a mouse click in JavaScript

Simulate a click with JavaScript for the element in the above video.

    var clickEvent = document.createEvent("MouseEvents");
    clickEvent.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0,
        false, false, false, false, 0, null);

    var element = document.querySelectorAll('[aria-label="bot (text channel)"]')[0];
    element.dispatchEvent(clickEvent);

Example of simulating a mouse click in JavaScript for some other site

    var clickEvent = document.createEvent("MouseEvents");
    clickEvent.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0,
        false, false, false, false, 0, null);

    var element = document.getElementsByClassName("rounded-md")[1];
    element.dispatchEvent(clickEvent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment