properly wait for reload after login

This commit is contained in:
Sebastian Hugentobler 2024-06-25 14:15:10 +02:00
parent 6bdf0f4010
commit 05ae5be02f
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0

14
nzz.js
View File

@ -18,6 +18,8 @@ const WAIT_TIMEOUT = 2000;
const TIMEOUT_MSG = `Timeout after ${WAIT_TIMEOUT / 1000} seconds.`;
const SEARCH_WAIT_TIMEOUT = 5000;
const SEARCH_TIMEOUT_MSG = `Timeout after ${SEARCH_WAIT_TIMEOUT / 1000} seconds.`;
const USER_AGENT =
"Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0";
Date.prototype.isoDate = function () {
return `${this.getFullYear()}-${String(this.getMonth() + 1).padStart(2, "0")}-${String(this.getDate()).padStart(2, "0")}`;
@ -153,6 +155,15 @@ async function login(driver, user, password) {
await driver.wait(until.elementIsVisible(submitButton), WAIT_TIMEOUT);
await submitButton.click();
await driver.switchTo().defaultContent();
const loginMenu = await driver.wait(
until.elementLocated(
By.css(".fup-login-open.fup-button.fup-s-menu-login-open"),
),
WAIT_TIMEOUT,
TIMEOUT_MSG,
);
await driver.wait(until.elementIsVisible(loginMenu), WAIT_TIMEOUT);
}
/**
@ -169,7 +180,7 @@ async function download(driver) {
await menu.click();
const download = await driver.wait(
until.elementLocated(By.css(".fup-s-menu-download-edition")),
until.elementLocated(By.css(".fup-s-menu-download-edition-confirmation")),
WAIT_TIMEOUT,
TIMEOUT_MSG,
);
@ -247,6 +258,7 @@ async function run(from, to, user, password, outDir) {
const fxOptions = new fx.Options()
// .addArguments("-headless")
.setPreference("pdfjs.disabled", true)
.setPreference("general.useragent.override", USER_AGENT)
.setPreference("browser.helperApps.neverAsk.openFile", "application/pdf")
.setPreference("browser.download.folderList", 2)
.setPreference("browser.download.manager.showWhenStartingout", false)