I want to manipulate an Intranet site with Javascript and I have done the following functions which work well, but if I run them one by one:
1: function (){
var list = document.getElementsByName("filter");
for (var i=0; i<list.length; i++) list[i].click();
},
2: function (){
var list = document.getElementsByClassName("ui-icon ui-icon-pencil tiptip");
for (var i=0; i<list.length; i++) list[i].click();
},
3: function (){
for(var i = 0, len = document.links.length; i < len; i += 1) {
if(document.links[i].textContent === "Configuration ") {
document.links[i].click();
}
}
},
4: function (){
var x = document.getElementsByName("configurations[]");
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "checkbox") {
x[i].checked = true;
}
}
},
My goal is to launch all the functions at once but I have to wait for the page to load before making the second click then the third then the fourth.
with the following code I have to run my function four times to get the four clicks
function (){
//function 1
var list = document.getElementsByName("filter");
for (var i=0; i<list.length; i++) list[i].click();
//function 2
var list = document.getElementsByClassName("ui-icon ui-icon-pencil tiptip");
for (var i=0; i<list.length; i++) list[i].click();
//function 3
for(var i = 0, len = document.links.length; i < len; i += 1) {
if(document.links[i].textContent === "Configuration ") {
document.links[i].click();
}
}
//function 4
var x = document.getElementsByName("configurations[]");
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "checkbox") {
x[i].checked = true;
}
}
},
the method
`setTimeout(() => {
var list = document.getElementsByName("filter");
for (var i=0; i<list.length; i++) list[i].click();
}, 3000)
setTimeout(() => {
var list = document.getElementsByClassName("ui-icon ui-icon-pencil tiptip");
for (var i=0; i<list.length; i++) list[i].click();
}, 3000)`
and the method
document.addEventListener("DOMContentLoaded", () => {
var list = document.getElementsByName("filter");
for (var i=0; i<list.length; i++) list[i].click();
});
document.addEventListener("DOMContentLoaded", () => {
var list = document.getElementsByClassName("ui-icon ui-icon-pencil tiptip");
for (var i=0; i<list.length; i++) list[i].click();
});
Also don’t work, If you have any idea please i will be grateful.