fix: replace wait_for_function with time.sleep to not block Teams dialog loading
This commit is contained in:
parent
1a9d6b2835
commit
31fce03012
@ -106,52 +106,44 @@ class Resolver:
|
|||||||
|
|
||||||
print(f" '{display_name}' via '{strategy}' geklickt — warte auf Dialog...")
|
print(f" '{display_name}' via '{strategy}' geklickt — warte auf Dialog...")
|
||||||
|
|
||||||
print(f" Warte auf E-Mail-Adresse im Dialog (bis 30s)...")
|
# Do NOT poll with wait_for_selector/wait_for_function —
|
||||||
try:
|
# Playwright's JS polling blocks Teams' async loading of the dialog.
|
||||||
# Wait directly for an email address to appear in the lpc-card light DOM.
|
# Simply wait for the dialog to load without interference.
|
||||||
# This covers both slow dialog opening AND slow content loading.
|
time.sleep(5)
|
||||||
self._page.wait_for_function(
|
|
||||||
r"""() => {
|
|
||||||
const card = document.querySelector('.lpc_ip_root_class lpc-card');
|
|
||||||
if (!card) return false;
|
|
||||||
const EMAIL_RE = /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/;
|
|
||||||
if (EMAIL_RE.test(card.textContent)) return true;
|
|
||||||
if (card.shadowRoot && EMAIL_RE.test(card.shadowRoot.textContent)) return true;
|
|
||||||
return false;
|
|
||||||
}""",
|
|
||||||
timeout=30_000,
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
card_text = self._page.evaluate("""() => {
|
|
||||||
const card = document.querySelector('.lpc_ip_root_class lpc-card');
|
|
||||||
if (!card) return '(kein lpc-card)';
|
|
||||||
return card.textContent.trim().substring(0, 200);
|
|
||||||
}""") or "(leer)"
|
|
||||||
print(f" Profil-Dialog Timeout — Light-DOM-Inhalt: {card_text!r}")
|
|
||||||
self._page.keyboard.press("Escape")
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
email = self._page.evaluate(r"""() => {
|
email = self._page.evaluate(r"""() => {
|
||||||
const EMAIL_RE = /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/;
|
const EMAIL_RE = /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/;
|
||||||
const card = document.querySelector('.lpc_ip_root_class lpc-card');
|
const card = document.querySelector('.lpc_ip_root_class lpc-card');
|
||||||
if (!card) return null;
|
if (!card) return '__NO_CARD__';
|
||||||
// Light DOM (slotted content)
|
// Light DOM (slotted content inserted into <slot> elements)
|
||||||
const lightLink = card.querySelector('a[href*="mailto:"]');
|
const lightLink = card.querySelector('a[href*="mailto:"]');
|
||||||
if (lightLink) return lightLink.href.replace('mailto:', '').trim();
|
if (lightLink) return lightLink.href.replace('mailto:', '').trim();
|
||||||
const lightMatch = card.textContent.match(EMAIL_RE);
|
const lightMatch = card.textContent.match(EMAIL_RE);
|
||||||
if (lightMatch) return lightMatch[0];
|
if (lightMatch) return lightMatch[0];
|
||||||
// Shadow root
|
// Shadow root fallback
|
||||||
if (card.shadowRoot) {
|
if (card.shadowRoot) {
|
||||||
const shadowMatch = card.shadowRoot.textContent.match(EMAIL_RE);
|
const shadowMatch = card.shadowRoot.textContent.match(EMAIL_RE);
|
||||||
if (shadowMatch) return shadowMatch[0];
|
if (shadowMatch) return shadowMatch[0];
|
||||||
}
|
}
|
||||||
return null;
|
return '__NO_EMAIL__' + card.textContent.trim().substring(0, 200);
|
||||||
}""")
|
}""")
|
||||||
self._page.keyboard.press("Escape")
|
|
||||||
time.sleep(0.3)
|
if not email or email == '__NO_CARD__':
|
||||||
return email or None
|
print(f" Kein Profil-Dialog erschienen.")
|
||||||
except Exception as e:
|
self._page.keyboard.press("Escape")
|
||||||
print(f" Fehler beim Lesen: {e}")
|
return None
|
||||||
|
|
||||||
|
if email.startswith('__NO_EMAIL__'):
|
||||||
|
print(f" Dialog offen, E-Mail nicht gefunden. Inhalt: {email[12:150]!r}")
|
||||||
|
self._page.keyboard.press("Escape")
|
||||||
|
return None
|
||||||
|
|
||||||
|
self._page.keyboard.press("Escape")
|
||||||
|
time.sleep(0.3)
|
||||||
|
return email
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f" Fehler beim Lesen des Profil-Dialogs: {e}")
|
||||||
self._page.keyboard.press("Escape")
|
self._page.keyboard.press("Escape")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user