fix(scraper): improve navigation and click reliability for export [32788f42]
This commit is contained in:
@@ -317,32 +317,43 @@ async def generate_pdf(job_id: str, account_type: str):
|
|||||||
if not login(driver, username, password):
|
if not login(driver, username, password):
|
||||||
raise HTTPException(status_code=401, detail="Login failed.")
|
raise HTTPException(status_code=401, detail="Login failed.")
|
||||||
|
|
||||||
# 1. Navigate to names list page (where the export button lives)
|
# 1. Navigate to job settings page first
|
||||||
reg_url = f"https://app.fotograf.de/config_children/view_names_list/{job_id}"
|
job_url = f"https://app.fotograf.de/config_jobs_settings/index/{job_id}"
|
||||||
logger.info(f"Navigating to names list (Personen): {reg_url}")
|
logger.info(f"Navigating to job main page: {job_url}")
|
||||||
driver.get(reg_url)
|
driver.get(job_url)
|
||||||
wait = WebDriverWait(driver, 30)
|
wait = WebDriverWait(driver, 30)
|
||||||
|
|
||||||
|
# Get Institution Name for PDF
|
||||||
try:
|
try:
|
||||||
institution = driver.find_element(By.TAG_NAME, "h1").text.strip()
|
institution = driver.find_element(By.TAG_NAME, "h1").text.strip()
|
||||||
logger.debug(f"Detected institution name: {institution}")
|
logger.debug(f"Detected institution name: {institution}")
|
||||||
except:
|
except:
|
||||||
institution = "Fotoauftrag"
|
institution = "Fotoauftrag"
|
||||||
|
|
||||||
logger.info("Triggering CSV Export...")
|
# 1.5 Click on the "Personen" tab
|
||||||
export_btn = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, SELECTORS["export_dropdown"])))
|
logger.info("Clicking on 'Personen' tab...")
|
||||||
export_btn.click()
|
personen_tab = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-qa-id='link:photo-jobs-tabs-names_list']")))
|
||||||
|
personen_tab.click()
|
||||||
|
|
||||||
|
# Wait for the export button to become present on the new tab
|
||||||
|
logger.info("Waiting for Export Dropdown...")
|
||||||
|
export_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, SELECTORS["export_dropdown"]))))
|
||||||
|
|
||||||
|
# Scroll to it and click via JS to avoid obscuring elements
|
||||||
|
driver.execute_script("arguments[0].scrollIntoView(true);", export_btn)
|
||||||
|
time.sleep(1) # small pause after scroll
|
||||||
|
logger.info("Clicking Export Dropdown...")
|
||||||
|
driver.execute_script("arguments[0].click();", export_btn)
|
||||||
|
|
||||||
logger.debug("Export dropdown clicked, waiting for menu items...")
|
logger.debug("Export dropdown clicked, waiting for menu items...")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
csv_btn = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, SELECTORS["export_csv_link"])))
|
csv_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, SELECTORS["export_csv_link"]))))
|
||||||
csv_btn.click()
|
logger.info("CSV Export button found. Clicking...")
|
||||||
logger.info("CSV Export button clicked.")
|
driver.execute_script("arguments[0].click();", csv_btn)
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
logger.error("CSV Button not found after clicking dropdown.")
|
|
||||||
take_error_screenshot(driver, "csv_button_missing")
|
|
||||||
raise HTTPException(status_code=500, detail="CSV Export Button konnte nicht gefunden werden.")
|
|
||||||
|
|
||||||
# Wait for file to appear
|
# Wait for file to appear
|
||||||
logger.debug("Waiting for CSV file in download directory...")
|
logger.debug("Waiting for CSV file in download directory...")
|
||||||
|
|||||||
Reference in New Issue
Block a user