-1

There is a div element on the page, by clicking on it a menu with a choice of the displayed number of elements is created.

Menu:

menu

How to call this action through the console (onMouseDown React)? Code: code

Fabio Mendes Soares
  • 1,357
  • 5
  • 20
  • 30
  • I am writing a chrome extension for the site, and the first step I need is to show all the elements on the site. The menu is already written to React on the onMouseDown event, click does not work. – Владимир Комяк Feb 07 '21 at 00:44

2 Answers2

1

In the console you want to grab your element and then use a dispatch event to simulate a mouseover or click

var div = document.querySelector("#myDiv");
var myEventToDispatch = new MouseEvent("click"); //or "mousedown", whichever you need
div.dispatchEvent(myEventToDispatch);

These three lines in your console should do the trick. Checkout: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent for more options

Da Mahdi03
  • 1,468
  • 1
  • 9
  • 18
  • I am writing a chrome extension for the site, and the first step I need is to show all the elements on the site. The menu is already written to React on the onMouseDown event, click does not work. – Владимир Комяк Feb 07 '21 at 00:44
0

found a solution, works in practice. The menu implementation on the site consisted of several nested divs and one input. None of these elements responded to the click () function. The solution below solved my problem and the next steps I needed.

<pre><code>
var MENU = IFrame.contentDocument.getElementsByClassName("class box menu")[0]; // getElementsById, getElementsByTag[0] ....
MENU = MENU.getElementsByTagName("div");
var MaxList = MENU[1].getElementsByTagName("input")[0];
if(MaxList != undefined)
{
    if(MENU[0].textContent != "100 items")
    {
        // focus menu
        MaxList.focus();
        var e = new KeyboardEvent(
            "keydown", 
            {
                bubbles : true, 
                cancelable : true, 
                key : "ArrowDown", 
                char : "ArrowDown", 
                shiftKey : true
            }
        );
        
        // scroll down the list
        MaxList.dispatchEvent(e);
        MaxList.dispatchEvent(e);
        MaxList.dispatchEvent(e);
        
        // choice
        e = new KeyboardEvent(
            "keydown", 
            {
                bubbles : true, 
                cancelable : true, 
                key : "Enter", 
                char : "Enter", 
                shiftKey : true
            }
        );
        MaxList.dispatchEvent(e);                   
    }
}
</code></pre>

VKomyak (Volt_Nerd)