I'm tasked with crawling website built with React. I'm trying to fill in input fields and submitting the form using javascript injects to the page (either selenium or webview in mobile). This works like a charm on every other site + technology but React seems to be a real pain.
so here is a sample code
var email = document.getElementById( 'email' );
email.value = '[email protected]';
I the value changes on the DOM input element, but the React does not trigger the change event.
I've been trying plethora of different ways to get the React to update the state.
var event = new Event('change', { bubbles: true });
email.dispatchEvent( event );
no avail
var event = new Event('input', { bubbles: true });
email.dispatchEvent( event );
not working
email.onChange( event );
not working
I cannot believe interacting with React has been made so difficult. I would greatly appreciate any help.
Thank you
The value changes on the DOM input element, but the React does not trigger the change event.
What change event are you expecting? If you're able to successfully fill out the input field, then why notdocument.forms[0].submit()
?.click()
on the form's submit button, or by triggering.submit()
on the form element itself, or by doing either of the above using thedispatchEvent()
method suggested below. However, manually clicking the submit button does submit the form properly. What am I missing?