fix: HOWOGE scroll down and click checkboxes before filling form
This commit is contained in:
parent
d6108ef762
commit
d03740ca20
1 changed files with 55 additions and 3 deletions
58
monitor.py
58
monitor.py
|
|
@ -452,11 +452,55 @@ class ApplicationHandler:
|
||||||
await page.wait_for_load_state("networkidle")
|
await page.wait_for_load_state("networkidle")
|
||||||
logger.info("[HOWOGE] Clicked button, waiting for form...")
|
logger.info("[HOWOGE] Clicked button, waiting for form...")
|
||||||
|
|
||||||
# Screenshot after clicking
|
# Scroll down the page to reveal checkboxes
|
||||||
|
await page.evaluate("window.scrollBy(0, 500)")
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
logger.info("[HOWOGE] Scrolled down to reveal checkboxes")
|
||||||
|
|
||||||
|
# Screenshot after clicking (before checkboxes)
|
||||||
screenshot_path = DATA_DIR / f"howoge_form_{listing['id']}.png"
|
screenshot_path = DATA_DIR / f"howoge_form_{listing['id']}.png"
|
||||||
await page.screenshot(path=str(screenshot_path))
|
await page.screenshot(path=str(screenshot_path), full_page=True)
|
||||||
logger.info(f"[HOWOGE] Saved form screenshot to {screenshot_path}")
|
logger.info(f"[HOWOGE] Saved form screenshot to {screenshot_path}")
|
||||||
|
|
||||||
|
# HOWOGE requires clicking checkboxes before the form fields become visible
|
||||||
|
# Look for and click all required checkboxes
|
||||||
|
checkboxes_clicked = 0
|
||||||
|
checkbox_selectors = [
|
||||||
|
'input[type="checkbox"]',
|
||||||
|
'.checkbox input',
|
||||||
|
'input[name*="datenschutz" i]',
|
||||||
|
'input[name*="privacy" i]',
|
||||||
|
'input[name*="einwillig" i]',
|
||||||
|
'input[name*="zustimmung" i]',
|
||||||
|
'input[name*="accept" i]',
|
||||||
|
]
|
||||||
|
|
||||||
|
for selector in checkbox_selectors:
|
||||||
|
checkboxes = await page.query_selector_all(selector)
|
||||||
|
for checkbox in checkboxes:
|
||||||
|
try:
|
||||||
|
if await checkbox.is_visible() and not await checkbox.is_checked():
|
||||||
|
await checkbox.scroll_into_view_if_needed()
|
||||||
|
await checkbox.click()
|
||||||
|
checkboxes_clicked += 1
|
||||||
|
logger.info(f"[HOWOGE] Clicked checkbox")
|
||||||
|
await asyncio.sleep(0.3)
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"[HOWOGE] Checkbox click failed: {e}")
|
||||||
|
|
||||||
|
if checkboxes_clicked > 0:
|
||||||
|
logger.info(f"[HOWOGE] Clicked {checkboxes_clicked} checkboxes")
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
# Screenshot after clicking checkboxes
|
||||||
|
screenshot_path = DATA_DIR / f"howoge_after_checkboxes_{listing['id']}.png"
|
||||||
|
await page.screenshot(path=str(screenshot_path), full_page=True)
|
||||||
|
logger.info(f"[HOWOGE] Saved after-checkboxes screenshot")
|
||||||
|
|
||||||
|
# Scroll back up to find the form fields
|
||||||
|
await page.evaluate("window.scrollTo(0, 0)")
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
# Fill in the contact form
|
# Fill in the contact form
|
||||||
# Look for name fields (Vorname, Nachname)
|
# Look for name fields (Vorname, Nachname)
|
||||||
vorname_field = await page.query_selector('input[name*="vorname" i], input[name*="firstname" i], input[placeholder*="Vorname" i], input#vorname')
|
vorname_field = await page.query_selector('input[name*="vorname" i], input[name*="firstname" i], input[placeholder*="Vorname" i], input#vorname')
|
||||||
|
|
@ -465,16 +509,22 @@ class ApplicationHandler:
|
||||||
|
|
||||||
form_filled = False
|
form_filled = False
|
||||||
if vorname_field:
|
if vorname_field:
|
||||||
|
await vorname_field.scroll_into_view_if_needed()
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
await vorname_field.fill(FORM_VORNAME)
|
await vorname_field.fill(FORM_VORNAME)
|
||||||
logger.info(f"[HOWOGE] Filled Vorname: {FORM_VORNAME}")
|
logger.info(f"[HOWOGE] Filled Vorname: {FORM_VORNAME}")
|
||||||
form_filled = True
|
form_filled = True
|
||||||
|
|
||||||
if nachname_field:
|
if nachname_field:
|
||||||
|
await nachname_field.scroll_into_view_if_needed()
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
await nachname_field.fill(FORM_NACHNAME)
|
await nachname_field.fill(FORM_NACHNAME)
|
||||||
logger.info(f"[HOWOGE] Filled Nachname: {FORM_NACHNAME}")
|
logger.info(f"[HOWOGE] Filled Nachname: {FORM_NACHNAME}")
|
||||||
form_filled = True
|
form_filled = True
|
||||||
|
|
||||||
if email_field:
|
if email_field:
|
||||||
|
await email_field.scroll_into_view_if_needed()
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
await email_field.fill(FORM_EMAIL)
|
await email_field.fill(FORM_EMAIL)
|
||||||
logger.info(f"[HOWOGE] Filled Email: {FORM_EMAIL}")
|
logger.info(f"[HOWOGE] Filled Email: {FORM_EMAIL}")
|
||||||
form_filled = True
|
form_filled = True
|
||||||
|
|
@ -482,12 +532,14 @@ class ApplicationHandler:
|
||||||
# Also look for phone field
|
# Also look for phone field
|
||||||
phone_field = await page.query_selector('input[type="tel"], input[name*="telefon" i], input[name*="phone" i]')
|
phone_field = await page.query_selector('input[type="tel"], input[name*="telefon" i], input[name*="phone" i]')
|
||||||
if phone_field:
|
if phone_field:
|
||||||
|
await phone_field.scroll_into_view_if_needed()
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
await phone_field.fill(FORM_PHONE)
|
await phone_field.fill(FORM_PHONE)
|
||||||
logger.info(f"[HOWOGE] Filled Phone: {FORM_PHONE}")
|
logger.info(f"[HOWOGE] Filled Phone: {FORM_PHONE}")
|
||||||
|
|
||||||
# Screenshot after filling form
|
# Screenshot after filling form
|
||||||
screenshot_path2 = DATA_DIR / f"howoge_filled_{listing['id']}.png"
|
screenshot_path2 = DATA_DIR / f"howoge_filled_{listing['id']}.png"
|
||||||
await page.screenshot(path=str(screenshot_path2))
|
await page.screenshot(path=str(screenshot_path2), full_page=True)
|
||||||
logger.info(f"[HOWOGE] Saved filled form screenshot to {screenshot_path2}")
|
logger.info(f"[HOWOGE] Saved filled form screenshot to {screenshot_path2}")
|
||||||
|
|
||||||
if form_filled:
|
if form_filled:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue