document.getElementsByName("Username")[0].value = 'FamilyGuy'
function myFunction(){
//pag 1, delay a second. Giving user name time to fill
document.getElementById("NextButton").click();
}
//delay
setTimeout(myFunction, 1000);
function myFunction(){
//page 2, delay a second. Giving passwrd time to fill befor logging in
document.getElementsByName("Password")[0].value = 'this1sth3p4ssw0rd!'
}
//delay
setTimeout(myFunction, 1000);
document.getElementById("LoginButton").click();
//I am using this extension using this extension
[1]: https://i.stack.imgur.com/LNMiJ.png
>Solution :
setTimeout is an asynchronous function. It doesn’t pause the execution of code that follows it.
This means that, in your example code, the two timeouts will run simultaneously, and your login button will be pressed immediately. To fix this, put the second timeout at the end of your first function, rather than in the main body of code. Also put the pressing of the login button inside the second function.
document.getElementsByName("Username")[0].value = 'FamilyGuy'
function myFunctionB(){
//page 2, delay a second. Giving passwrd time to fill befor logging in
document.getElementsByName("Password")[0].value = 'this1sth3p4ssw0rd!'
document.getElementById("LoginButton").click();
}
function myFunctionA(){
//pag 1, delay a second. Giving user name time to fill
document.getElementById("NextButton").click();
//delay
setTimeout(myFunctionB, 1000);
}
//delay
setTimeout(myFunctionA, 1000);
I don’t know the way the NextButton operates, but the use of a delay to wait until the Username value changes is probably unnecessary. Consider using the following code:
function myFunction(){
document.getElementsByName("Password")[0].value = 'this1sth3p4ssw0rd!'
document.getElementById("LoginButton").click();
}
document.getElementsByName("Username")[0].value = 'FamilyGuy'
document.getElementById("NextButton").click();
//delay
setTimeout(myFunction, 1000);