My mind is about to break trying to figure out this.
I'm trying to automate adding some machines to a list from the google chrome console, since the website is not mine and i do not have access to the code.
I have a big list of machine that i need to add to the right column, i can't import it so that's why i'm trying to automate the process.
This is my code:
// input box
var search = document.getElementById(
"CustomControl_ml_ms_m_si_m_tic_pc_xAssignedResources_m_computerSelector_WrappedSelector_ml_ms_m_si_m_tic_pc_xAssignedResources_m_computerSelector_WrappedSelector_mainGrid_ctl00_SearchBox"
);
// add to list btn
const addToList = document.querySelector(".scbMiddleCell input:nth-child(2)");
// first item on the left column
const primeraCelda = document.querySelector(".scgc");
// change the value of the input box
search.value = "XXX-MXXXX";
// create a keyup event
var ev = document.createEvent("Event");
ev.initEvent("keyup");
ev.which = ev.keyCode = 13;
// run the event, this way the ajax function kicks in and i'm left with only one item in the left column
search.dispatchEvent(ev);
setTimeout(() => {
// simulate the left item row selection
primeraCelda.click();
}, 1000);
setTimeout(() => {
// click on the button to add the item to the right column
addToList.click();
}, 1500);
Now this works only when i'm using a single value, if i create and array with values, and a foreach loop, it directly iterates through all the items in the array and only the last item gets added to the right column.
I can't figure out how to NOT iterate until the item is added to the right column.