V
V
Vinni372019-05-27 11:04:21
JavaScript
Vinni37, 2019-05-27 11:04:21

How to simulate mouse clicks on a React component?

Greetings. I am writing a small chrome extension for myself.
The question arose how to simulate a mouse click on a React component.
Tried through dispatchEvent and just click (through JQuery and native JS), the event is processed (caught through Breakpoint) but the application does not react to it.
Experiments were carried out in the browser console.
PS
With buttons, everything works well, a snag with drop-down selects on the form.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-05-27
@Vinni37


How to simulate mouse clicks on a React component?

Just like any other DOM element.
select.value = someValue;
select.dispatchEvent(new Event('change', { bubbles: true }));

C
Cr2ed, 2019-05-27
@Cr2ed

Try this approach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question