I'm working on an app in which I'm able to run my own Javascript inside browser context after opening a 3rd party website. As a sample website which is build on reactjs and has a login form, you can refer to this link.
I'm trying to fill the username and password in the form which is generated by reactjs. However, I'm not able to completely achieve it.
The closest codebase by which I'm able to set value into the username/password field and inside reactjs is:
function setNativeValue(element, value) {
element.focus();
element.click();
element.value = value;
element.defaultValue = value;
let tracker = element._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
let inputEvent = new Event("input", { target: element, bubbles: true });
inputEvent.simulated = true;
element.dispatchEvent(inputEvent);
}
document.getElementsByClassName("sc-qamJO")[0].click(); // login top button
setTimeout(function () {
setNativeValue(document.getElementsByClassName("sc-AxheI")[1], "username"); // username
setNativeValue(document.getElementsByClassName("sc-AxheI")[2], "password"); // password
setTimeout(function () {
document.getElementsByClassName("sc-fzpans")[3].click(); // login button
}, 1000);
}, 1000);
Problem:
However, I'm not able to automatically submit the reactjs form. It throws an error This field is required*
error, even though I have done everything correctly based on my understanding and google search suggestions. I'm not able to satisfy the field validators.
I have tried lot and lot of ways to automatically submit the form. Some of them are:
- Following all the methods provided on this stackoverflow question
- Getting the reactjs instance then trying to
setState. In this case,
.setState is not a function
error comes - This github issue comments is what I'm currently following to solve my problem
- I have also tried sequence of events like
mouseenter
mousedown
...keydown
keypress
keyup
and others, similar to what this person is doing
Can you please tell, what should I do, in order to satisfy the reactjs validators available in the login form, so that the form gets automatically submitted on website using javascript or jQuery.
Note - The sample website does not contains jQuery, so a pure Javascript code will also work in terms of understanding.
I'm using Chromium as a browser.