fix: wait for email to appear in lpc-card light DOM with 30s timeout
This commit is contained in:
parent
fab600fa07
commit
1a9d6b2835
@ -106,53 +106,52 @@ 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)...")
|
||||||
try:
|
try:
|
||||||
# The dialog can take several seconds to fully load — wait up to 15s
|
# Wait directly for an email address to appear in the lpc-card light DOM.
|
||||||
self._page.wait_for_selector(".lpc_ip_root_class", timeout=15_000)
|
# This covers both slow dialog opening AND slow content loading.
|
||||||
|
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:
|
except Exception:
|
||||||
print(f" Profil-Dialog für '{display_name}' erscheint nicht (Timeout).")
|
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")
|
self._page.keyboard.press("Escape")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Wait for slotted content to load inside the lpc-card
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
email = self._page.evaluate(r"""() => {
|
email = self._page.evaluate(r"""() => {
|
||||||
const lpcCard = document.querySelector('.lpc_ip_root_class lpc-card');
|
|
||||||
if (!lpcCard) return null;
|
|
||||||
|
|
||||||
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');
|
||||||
// 1. Slotted content = light DOM children of lpc-card (inserted into <slot>)
|
if (!card) return null;
|
||||||
const lightLink = lpcCard.querySelector('a[href*="mailto:"]');
|
// Light DOM (slotted content)
|
||||||
|
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 = lpcCard.textContent.match(EMAIL_RE);
|
|
||||||
if (lightMatch) return lightMatch[0];
|
if (lightMatch) return lightMatch[0];
|
||||||
|
// Shadow root
|
||||||
// 2. Shadow root of lpc-card
|
if (card.shadowRoot) {
|
||||||
if (lpcCard.shadowRoot) {
|
const shadowMatch = card.shadowRoot.textContent.match(EMAIL_RE);
|
||||||
const shadowLink = lpcCard.shadowRoot.querySelector('a[href*="mailto:"]');
|
|
||||||
if (shadowLink) return shadowLink.href.replace('mailto:', '').trim();
|
|
||||||
|
|
||||||
const shadowMatch = lpcCard.shadowRoot.textContent.match(EMAIL_RE);
|
|
||||||
if (shadowMatch) return shadowMatch[0];
|
if (shadowMatch) return shadowMatch[0];
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
// 3. Diagnostic: return light DOM text for inspection
|
|
||||||
return '__DEBUG__' + lpcCard.textContent.trim().substring(0, 300);
|
|
||||||
}""")
|
}""")
|
||||||
|
|
||||||
if email and email.startswith('__DEBUG__'):
|
|
||||||
print(f" Dialog offen, E-Mail nicht gefunden. Inhalt: {email[9:200]!r}")
|
|
||||||
email = None
|
|
||||||
|
|
||||||
self._page.keyboard.press("Escape")
|
self._page.keyboard.press("Escape")
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
return email or None
|
return email or None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" Fehler beim Lesen des Profil-Dialogs: {e}")
|
print(f" Fehler beim Lesen: {e}")
|
||||||
self._page.keyboard.press("Escape")
|
self._page.keyboard.press("Escape")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user