fix: search slotted light DOM content, increase dialog timeout to 15s
This commit is contained in:
parent
539e1a916b
commit
fab600fa07
@ -107,74 +107,46 @@ class Resolver:
|
|||||||
print(f" '{display_name}' via '{strategy}' geklickt — warte auf Dialog...")
|
print(f" '{display_name}' via '{strategy}' geklickt — warte auf Dialog...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Wait for the profile dialog to open
|
# The dialog can take several seconds to fully load — wait up to 15s
|
||||||
# Could be lpc_ip_root_class (hover card) or a role="dialog" modal
|
self._page.wait_for_selector(".lpc_ip_root_class", timeout=15_000)
|
||||||
self._page.wait_for_selector(
|
|
||||||
".lpc_ip_root_class, [role='dialog']",
|
|
||||||
timeout=6_000,
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
print(f" Profil-Dialog für '{display_name}' erscheint nicht.")
|
print(f" Profil-Dialog für '{display_name}' erscheint nicht (Timeout).")
|
||||||
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:
|
||||||
# Check which dialog appeared and extract email
|
email = self._page.evaluate(r"""() => {
|
||||||
# Try shadow DOM of lpc-card first
|
|
||||||
email = self._page.evaluate("""() => {
|
|
||||||
// Check lpc-card shadow DOM
|
|
||||||
const lpcCard = document.querySelector('.lpc_ip_root_class lpc-card');
|
const lpcCard = document.querySelector('.lpc_ip_root_class lpc-card');
|
||||||
if (lpcCard && lpcCard.shadowRoot) {
|
if (!lpcCard) return null;
|
||||||
const link = lpcCard.shadowRoot.querySelector('a[href*="mailto:"]');
|
|
||||||
if (link) return link.href.replace('mailto:', '').trim();
|
const EMAIL_RE = /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/;
|
||||||
// Also check text content for email pattern
|
|
||||||
const text = lpcCard.shadowRoot.textContent;
|
// 1. Slotted content = light DOM children of lpc-card (inserted into <slot>)
|
||||||
const match = text.match(/[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}/);
|
const lightLink = lpcCard.querySelector('a[href*="mailto:"]');
|
||||||
if (match) return match[0];
|
if (lightLink) return lightLink.href.replace('mailto:', '').trim();
|
||||||
|
|
||||||
|
const lightMatch = lpcCard.textContent.match(EMAIL_RE);
|
||||||
|
if (lightMatch) return lightMatch[0];
|
||||||
|
|
||||||
|
// 2. Shadow root of lpc-card
|
||||||
|
if (lpcCard.shadowRoot) {
|
||||||
|
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];
|
||||||
}
|
}
|
||||||
// Check regular dialog
|
|
||||||
const dialog = document.querySelector("[role='dialog']");
|
// 3. Diagnostic: return light DOM text for inspection
|
||||||
if (dialog) {
|
return '__DEBUG__' + lpcCard.textContent.trim().substring(0, 300);
|
||||||
const link = dialog.querySelector('a[href*="mailto:"]');
|
|
||||||
if (link) return link.href.replace('mailto:', '').trim();
|
|
||||||
const text = dialog.textContent;
|
|
||||||
const match = text.match(/[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}/);
|
|
||||||
if (match) return match[0];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}""")
|
}""")
|
||||||
|
|
||||||
if not email:
|
if email and email.startswith('__DEBUG__'):
|
||||||
# Wait a bit more for the dialog to fully load (two-stage)
|
print(f" Dialog offen, E-Mail nicht gefunden. Inhalt: {email[9:200]!r}")
|
||||||
time.sleep(2)
|
email = None
|
||||||
email = self._page.evaluate("""() => {
|
|
||||||
function findEmail(root) {
|
|
||||||
const link = root.querySelector('a[href*="mailto:"]');
|
|
||||||
if (link) return link.href.replace('mailto:', '').trim();
|
|
||||||
const match = root.textContent.match(/[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}/);
|
|
||||||
if (match) return match[0];
|
|
||||||
// Search shadow roots recursively
|
|
||||||
for (const el of root.querySelectorAll('*')) {
|
|
||||||
if (el.shadowRoot) {
|
|
||||||
const found = findEmail(el.shadowRoot);
|
|
||||||
if (found) return found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return findEmail(document.body);
|
|
||||||
}""")
|
|
||||||
|
|
||||||
if not email:
|
|
||||||
# Diagnostic: show what's in the dialog
|
|
||||||
content = self._page.evaluate("""() => {
|
|
||||||
const d = document.querySelector('.lpc_ip_root_class lpc-card');
|
|
||||||
if (d && d.shadowRoot) return 'shadow: ' + d.shadowRoot.textContent.trim().substring(0, 200);
|
|
||||||
const r = document.querySelector("[role='dialog']");
|
|
||||||
if (r) return 'dialog: ' + r.textContent.trim().substring(0, 200);
|
|
||||||
return '(nichts gefunden)';
|
|
||||||
}""")
|
|
||||||
print(f" Dialog offen, E-Mail nicht gefunden. Inhalt: {content!r}")
|
|
||||||
|
|
||||||
self._page.keyboard.press("Escape")
|
self._page.keyboard.press("Escape")
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user