Hi everyone!
I am having some issues creating a small JavaScript program.
I need to download a report from a website every 10 minutes and I would like to do this automatically.
Running below command work and start the download:
window.open(“DownloadURL”,"_self") ;
The only problem is I need to login with user name and password before being able to access the file.
Now I have 2 questions:
- Can I keep running a script if the first if the first command will open a link?
ex:
window.open(“URL to authentication”, “_top”);
.....rest of the script.
- I am trying to use below script to log in automatically on the browser console:
var pwd="password"; //set password
var usr="user name"; //set username
var inputs=document.getElementsByTagName("input"); //look for all inputs
for(var i=0;i<inputs.length;i++){{ //for each input on document
var input=inputs[i]; //look at input
if(input.type=="password"&&(input.name.toLowerCase().indexOf("auth")==-1)){
{input.value=pwd}
}
if(input.type=="text"&&(input.name.toLowerCase().indexOf("login")!=-1||input.name.toLowerCase().indexOf("user")!=-1||input.name=="AgentAccount")){
{input.value=usr}
}
}};
document.querySelector('.__progress-button-content').click(); // click on login button
running this, the user name and the password field are populated with the correct variables, but I get an error message as if I insert the wrong password and username (which are correct for sure).
Can anyone help me with this issue or suggest me a different approach?
I really hope my explanation was not too chaotic!
Thanks!!!