Next.js Discord

Discord Forum

Triggering a button click event from the console

Unanswered
Mini Rex posted this in #help-forum
Open in Discord
Mini RexOP
I'm writing A/B tests and I can't trigger a button click from my code. React uses synthetic events and I tried using
var testEvent = new PointerEvent("click");
testEvent.nativeEvent = {detail:1}
elem.__reactProps$3jcigo40r49.onClick(testEvent);

with no luck. I see that when I press and hold the button, style="user-select: none;" is added while holding.
Anyone know how to get it to trigger?

7 Replies

Mini RexOP
Tried that first. It doesn't work for this button
Site in question is https://quote.staysure.co.uk/
$('#cover-type-page-submit-button').click()
@Mini Rex Site in question is https://quote.staysure.co.uk/ $('#cover-type-page-submit-button').click()
it looks like there is no onClick event on the button itself. Add a click event to the button and then you can execute it via js
Mini RexOP
I'm trying to tigger the continue button from another place not add a new event to it. The event connected to react is there
@Mini Rex ?