I have a website with a Username textbox and a Password textbox and a Sign in button for login. On that website if I login by entering the username and password manually, it works fine. But when I do it using JS like this
document.getElementById('userId').value = 'name';
document.getElementById('pwd').value = 'password';
And click the login button, it shows error "Please enter a username and password for login", i.e. it's not picking up the values.
I also tried despatching the event like this but no luck
var username = document.getElementById('userId');
username.value = 'name';
if ('createEvent' in document) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent('change', false, true);
username.dispatchEvent(evt);
} else {
username.fireEvent('onchange');
}
var password = document.getElementById('pwd');
password.value = 'password';
if ('createEvent' in document) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent('change', false, true);
password.dispatchEvent(evt);
} else {
password.fireEvent('onchange');
}
So my only question to experts out here is what should be the Javascript/JQuery code that I can write which will blueprint the logic of changing the textbox value manually.