diff --git a/backend/services/clickTtPlayerRegistrationService.js b/backend/services/clickTtPlayerRegistrationService.js index 763171a0..f2b24273 100644 --- a/backend/services/clickTtPlayerRegistrationService.js +++ b/backend/services/clickTtPlayerRegistrationService.js @@ -102,7 +102,7 @@ class ClickTtPlayerRegistrationService { await this._openAuthenticatedClickTt(page, { username, password, trace }); await this._selectClubContext(page, associationMemberNumber, trace); await this._openApplicationEntry(page, trace); - await this._fillSearchForm(page, memberJson); + await this._fillSearchForm(page, memberJson, trace); await this._clickByText(page, 'Personen suchen', trace); await page.waitForLoadState('domcontentloaded'); @@ -318,6 +318,10 @@ class ClickTtPlayerRegistrationService { async _openApplicationEntry(page, trace) { await this._dismissConsentOverlays(page, trace); + if (await page.locator('form.search-query').count()) { + return true; + } + const labels = [ 'Spielberechtigungen beantragen', 'Spielberechtigungen' @@ -326,11 +330,28 @@ class ClickTtPlayerRegistrationService { for (const label of labels) { if (await this._hasTextTarget(page, label)) { await this._clickByText(page, label, trace); - return true; + await page.waitForLoadState('domcontentloaded'); + await this._dismissConsentOverlays(page, trace); + break; } } - throw new HttpError('Click-TT-Element nicht gefunden: Spielberechtigungen', 500); + if (await page.locator('form.search-query').count()) { + return true; + } + + if (await this._hasTextTarget(page, 'Spielberechtigungen beantragen...')) { + await this._clickByText(page, 'Spielberechtigungen beantragen...', trace); + await page.waitForLoadState('domcontentloaded'); + await this._dismissConsentOverlays(page, trace); + return true; + } + + if (await page.locator('form.search-query').count()) { + return true; + } + + throw new HttpError('Click-TT-Element nicht gefunden: Spielberechtigungen / Spielberechtigungen beantragen...', 500); } async _selectClubContext(page, associationMemberNumber, trace) { @@ -356,13 +377,17 @@ class ClickTtPlayerRegistrationService { return false; } - async _fillSearchForm(page, member) { - await this._fillFirstAvailable(page, [ - 'input[name*=".1"]', - 'input[type="text"]' - ], member.lastName); - await this._fillNthTextInput(page, 1, member.firstName); - await this._fillNthTextInput(page, 2, formatGermanDate(member.birthDate)); + async _fillSearchForm(page, member, trace) { + const searchForm = page.locator('form.search-query').first(); + if (!(await searchForm.count())) { + throw new HttpError('Click-TT-Suchformular für Spielberechtigungen nicht gefunden', 500); + } + + this._trace(trace, 'step', { name: 'fill-search-form' }); + + await searchForm.locator('input[name$=".1"]').first().fill(member.lastName); + await searchForm.locator('input[name$=".3"]').first().fill(member.firstName); + await searchForm.locator('input[name$=".5"]').first().fill(formatGermanDate(member.birthDate)); } async _fillApplicationForm(page, member, email) {