fix(myTischtennis): enhance consent dialog handling during login process

- Refactored consent dialog handling to improve reliability by implementing a dedicated function that attempts to dismiss the dialog with multiple selectors.
- Added a delay mechanism to account for asynchronous rendering of the consent dialog, ensuring it is accepted promptly.
- Improved logging to provide clearer feedback on which selector was used to accept the consent dialog.
This commit is contained in:
Torsten Schulz (local)
2026-03-04 08:29:18 +01:00
parent 3df8f6fd81
commit d5fe531664

View File

@@ -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