diff --git a/backend/clients/myTischtennisClient.js b/backend/clients/myTischtennisClient.js index 0c4fd820..9f6260ed 100644 --- a/backend/clients/myTischtennisClient.js +++ b/backend/clients/myTischtennisClient.js @@ -368,24 +368,41 @@ class MyTischtennisClient { await page.goto(`${this.baseURL}/login?next=%2F`, { waitUntil: 'domcontentloaded', timeout: 45000 }); console.log('[myTischtennisClient.playwright] Page loaded'); - // Best-effort: Consent/overlay dialogs that can block form interaction. - const consentSelectors = [ - '#onetrust-accept-btn-handler', - 'button:has-text("Alle akzeptieren")', - 'button:has-text("Akzeptieren")', - 'button:has-text("Einverstanden")' - ]; - for (const selector of consentSelectors) { - try { - const button = page.locator(selector).first(); - if (await button.count()) { - await button.click({ timeout: 1500 }); - console.log('[myTischtennisClient.playwright] Consent dialog accepted'); - break; + // Dismiss CMP/consent dialog. The dialog can appear with a delay, so we wait + // briefly for it and try multiple selectors including the explicit "Akzeptieren" button. + const acceptConsentDialog = async (waitMs = 0) => { + if (waitMs > 0) await page.waitForTimeout(waitMs); + const consentSelectors = [ + '#onetrust-accept-btn-handler', + 'button:has-text("Alle akzeptieren")', + 'button:has-text("Akzeptieren")', + 'button:has-text("Einverstanden")', + 'button:has-text("Zustimmen")', + '[data-testid="accept-button"]', + '.cmp-accept-all', + '.accept-all-btn' + ]; + for (const selector of consentSelectors) { + try { + const button = page.locator(selector).first(); + if (await button.count()) { + await button.click({ timeout: 2500 }); + console.log('[myTischtennisClient.playwright] Consent dialog accepted via:', selector); + await page.waitForTimeout(600); + return true; + } + } catch (_e) { + // ignore, try next selector } - } catch (_e) { - // ignore and try next selector } + return false; + }; + + // First attempt immediately after page load. + const consentAcceptedEarly = await acceptConsentDialog(0); + // Second attempt with a short delay if not accepted yet (CMP often renders async). + if (!consentAcceptedEarly) { + await acceptConsentDialog(2500); } // Fill credentials