Initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
(async () => {
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
const getAllDocuments = () => {
|
||||
const docs = [document];
|
||||
|
||||
const scan = doc => {
|
||||
[...doc.querySelectorAll("iframe, frame")].forEach(frame => {
|
||||
try {
|
||||
if (frame.contentDocument) {
|
||||
docs.push(frame.contentDocument);
|
||||
scan(frame.contentDocument);
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
};
|
||||
|
||||
scan(document);
|
||||
return docs;
|
||||
};
|
||||
|
||||
const waitForElement = async (selector, timeout = 20000) => {
|
||||
const start = Date.now();
|
||||
|
||||
while (Date.now() - start < timeout) {
|
||||
for (const doc of getAllDocuments()) {
|
||||
const el = doc.querySelector(selector);
|
||||
if (el) return el;
|
||||
}
|
||||
|
||||
await sleep(300);
|
||||
}
|
||||
|
||||
throw new Error(`No se encontró: ${selector}`);
|
||||
};
|
||||
|
||||
const clickElement = async selector => {
|
||||
const el = await waitForElement(selector);
|
||||
el.scrollIntoView({ block: "center", inline: "center" });
|
||||
await sleep(300);
|
||||
el.click();
|
||||
return el;
|
||||
};
|
||||
|
||||
await clickElement("#id_menu_prj_generate");
|
||||
|
||||
await sleep(1500);
|
||||
|
||||
await clickElement('input[name="avancar"][value="Generate"]');
|
||||
})();
|
||||
Reference in New Issue
Block a user