I want to automate a process that requiere to download a file.
I have to do a search, specifing a string in a search box and then clicking buttom (called: "ctl00$MainContent$BtnBusqueda"). Once the results are showed, you can download an unique results to a file with a buttom (called: "BtnDescarga").
I already could input the string to the search box and perform the search with this (iterable to automate over a string array):
function setUUID(element, index, array) {
document.getElementsByName("ctl00$MainContent$TxtUUID")[0].value=element;
document.getElementsByName("ctl00$MainContent$BtnBusqueda")[0].click();
}
So, I can call that over a string array with: array.forEach(setUUID)
I tried to finish the problem downloading the file with this:
function setUUID(element, index, array) {
document.getElementsByName("ctl00$MainContent$TxtUUID")[0].value=element;
document.getElementsByName("ctl00$MainContent$BtnBusqueda")[0].click();
document.getElementsByName("BtnDescarga")[0].click();
}
But I get:
Uncaught TypeError: Cannot read properties of undefined (reading 'click')
at setUUID (<anonymous>:4:49)
at Array.forEach (<anonymous>)
at <anonymous>:1:7
I'm new in JavaScript but I barely understand that the element called "BtnDescarga" only appears when the search it's done, so, it "appends" to the document. Then, how before the search it doesnt exist, it can't be foundt.
So, any solution to this? Anyway to access to a new element in document that only appears when you click a buttom? or any better solution to this?
Thanks overall.