fix: retry username detection with split on 'von'/'of' and length validation

This commit is contained in:
Oliver Hofmann 2026-05-17 12:12:15 +02:00
parent 7c6aa4ccd7
commit 83642b2b8d

View File

@ -46,25 +46,25 @@ class Monitor:
print("Chat erkannt.")
def get_current_user_display_name(self) -> str:
# Wait for the Teams main UI to render (not a lobby/join page)
try:
self._page.wait_for_selector(
"[data-tid='me-control-display-name'], [aria-label*='Profilbild'], [aria-label*='Profile picture']",
timeout=15_000,
)
except Exception:
pass
for selector, transform in [
("[data-tid='me-control-display-name']", lambda el: el.inner_text().strip()),
("[aria-label*='Profilbild']", lambda el: (el.get_attribute("aria-label") or "").replace("Profilbild", "").strip()),
("[aria-label*='Profile picture']", lambda el: (el.get_attribute("aria-label") or "").replace("Profile picture", "").strip()),
]:
el = self._page.query_selector(selector)
if el:
name = transform(el)
if name:
return name
# Retry up to 10s — Teams loads the display name asynchronously
for _ in range(10):
for selector, extractor in [
("[data-tid='me-control-display-name']",
lambda el: el.inner_text().strip()),
("[aria-label*='Profilbild']",
lambda el: (el.get_attribute("aria-label") or "").split("von ", 1)[-1].strip(" .")),
("[aria-label*='Profile picture']",
lambda el: (el.get_attribute("aria-label") or "").split("of ", 1)[-1].strip(" .")),
]:
try:
el = self._page.query_selector(selector)
if el:
name = extractor(el)
if name and len(name) > 2:
return name
except Exception:
pass
self._page.wait_for_timeout(1000)
name = input("Benutzername nicht erkannt. Bitte deinen Teams-Anzeigenamen eingeben: ").strip()
if not name: