Triggering a button click event from the console
Unanswered
Mini Rex posted this in #help-forum
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
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?
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 Rex 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?
you can use dom function for it.
Like that you click the element of your choice. That can be the button. No need for any special events
const elmt = document.getElementById('someid');
elmt.click();Like that you click the element of your choice. That can be the button. No need for any special events
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()
$('#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 jsMini 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 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
can you share how you creating the button as code?
@Mini Rex ?