I'm hoping to use javascript within tampermonkey to scrape https://www.intellizoom.com/ so I can be alerted immediately when any new jobs come in for me to accept (jobs can disappear within seconds if not acted on immediately). Unfortunately my login eventually expires, and the website redirects to https://www.intellizoom.com/login.
I therefore want to use a tampermonkey script matching the login URL to automatically log back in when needed.
I'm struggling to get this to work. First of, it seems you have to focus any input fields before they correctly accept any input from javascript. That works for adding the username and password, but just using focus() on the login button fails.
My test script successfully logs in if, before the message "click!" appears in the console, I physically click anywhere in the website page. (Hence the 5 second setTimeout to give me time to physically click - for test purposes). The login button then turns blue, and the .click(); javascript function then successfully submits the login details.
But, I can't find any way to simulate the physical click using javascript, all attempts to use click() on elements or on co-ordinates just does nothing (with no error messages in the console). Adding focus() before click() doesn't help either.
Can anyone figure out how to submit the login details for this website via javascript?
setTimeout(function(){
document.getElementById("email").focus();
document.getElementById("email").value = "username@Domain.co.uk";
document.getElementById("password").focus();
document.getElementById("password").value = "password";
},500);
setTimeout(function(){
console.log("click!");
document.getElementsByClassName("button large primary is-rounded")[0].click();
},3000);
UPDATE: The solution was kindly provided by Markfila - this code works:
setTimeout(function(){
document.getElementById("email").value = "username@Domain.co.uk";
document.getElementById("password").value = "password";
let event = new Event("blur");
document.getElementById("email").dispatchEvent(event);
document.getElementById("password").dispatchEvent(event);
document.getElementsByClassName("button large primary is-rounded")[0].click();
},100);
I've raised a follow up here question (since I'm not supposed to ask follow questions directly in here).