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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user