I wrote the following code which I run in Chrome Dev-Tools:
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo() {
counter = 1;
while (counter <= 363) {
document.getElementsByClassName('print')[1].click()
await sleep(5000);
document.getElementsByName('ctl00$PopupBody$printButtons')[0].click();
document.getElementsByName('ctl00$PopupBody$txtPageStart')[0].value = counter;
document.getElementsByName('ctl00$PopupBody$txtPageEnd')[0].value = counter + 10;
document.getElementsByClassName('ConfirmButton')[0].click();
counter+=10;
await sleep(5000);
}
}
demo()
I want to convert a file in a website into PDF so I use the print option to convert it to PDF. It allows up to 10 page each print so I want to write a code which does it for me. Basically it should open a model each time, fill the fields and click confirm (which close the modal). The problem is that after document.getElementsByClassName('print')[1].click()
it opens a modal and for some reason document
can't find ctl00$PopupBody$printButtons
. I guess it does not render the DOM. How can I "refresh" document
to use the current HTML?
EDIT: window.location.reload(true);
(and other methods like this one) do full page reload, the modal closes and the code stops running (reload dev-tools). I don't want to reload the page, just the HTML in document