fix: retry MH eligibility extraction to handle AngularJS late binding
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -213,33 +213,39 @@ class AutomationMassHealthEligibilityHistoryCheck:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for status_label, elig_flag in [("Eligible", "Y"), ("Ineligible", "N")]:
|
# AngularJS populates cell text after elements appear in the DOM.
|
||||||
rows = self.driver.find_elements(
|
# Retry a few times until a row with non-empty cell[2] is found.
|
||||||
By.XPATH,
|
for attempt in range(4):
|
||||||
f"//h4[text()='{status_label}']/following::table[1]/tbody/tr"
|
for status_label, elig_flag in [("Eligible", "Y"), ("Ineligible", "N")]:
|
||||||
)
|
rows = self.driver.find_elements(
|
||||||
for row in rows:
|
By.XPATH,
|
||||||
cells = row.find_elements(By.TAG_NAME, "td")
|
f"//h4[text()='{status_label}']/following::table[1]/tbody/tr"
|
||||||
if len(cells) < 3:
|
)
|
||||||
continue
|
for row in rows:
|
||||||
member_number = self._cell_text(cells[2])
|
cells = row.find_elements(By.TAG_NAME, "td")
|
||||||
norm_cell = self._normalize_id(member_number)
|
if len(cells) < 3:
|
||||||
norm_self = self._normalize_id(self.memberId)
|
continue
|
||||||
if norm_self and norm_cell and (norm_self in norm_cell or norm_cell in norm_self):
|
member_number = self._cell_text(cells[2])
|
||||||
full_name = self._cell_text(cells[4]) if len(cells) > 4 else ""
|
norm_cell = self._normalize_id(member_number)
|
||||||
plan_name = (
|
norm_self = self._normalize_id(self.memberId)
|
||||||
self._cell_text(cells[6]) if len(cells) > 6
|
if norm_self and norm_cell and (norm_self in norm_cell or norm_cell in norm_self):
|
||||||
else (self._cell_text(cells[-1]) if len(cells) > 4 else "")
|
full_name = self._cell_text(cells[4]) if len(cells) > 4 else ""
|
||||||
)
|
plan_name = (
|
||||||
name_parts = full_name.split()
|
self._cell_text(cells[6]) if len(cells) > 6
|
||||||
extracted = {
|
else (self._cell_text(cells[-1]) if len(cells) > 4 else "")
|
||||||
"eligibility": elig_flag,
|
)
|
||||||
"firstName": name_parts[0] if name_parts else "",
|
name_parts = full_name.split()
|
||||||
"lastName": " ".join(name_parts[1:]) if len(name_parts) > 1 else "",
|
extracted = {
|
||||||
"insurance": plan_name,
|
"eligibility": elig_flag,
|
||||||
}
|
"firstName": name_parts[0] if name_parts else "",
|
||||||
print(f"[extraction] MATCHED {status_label} → name='{full_name}' plan='{plan_name}'")
|
"lastName": " ".join(name_parts[1:]) if len(name_parts) > 1 else "",
|
||||||
return extracted
|
"insurance": plan_name,
|
||||||
|
}
|
||||||
|
print(f"[extraction] MATCHED {status_label} → name='{full_name}' plan='{plan_name}'")
|
||||||
|
return extracted
|
||||||
|
if attempt < 3:
|
||||||
|
print(f"[extraction] cells not yet populated (attempt {attempt + 1}), retrying...")
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
print(f"[extraction] No matching row for memberId='{self.memberId}'")
|
print(f"[extraction] No matching row for memberId='{self.memberId}'")
|
||||||
return {"eligibility": None}
|
return {"eligibility": None}
|
||||||
|
|||||||
Reference in New Issue
Block a user