fix: DDMA claim selects tooth number via row's ToothNumber{i} combobox
Tooth numbers on later treatment rows were skipped (element not interactable)
because the trigger was picked positionally from all 'filtrable' spans. Now
targets #ToothNumber{i}_input and its #ToothNumber{i}-ul listbox, and closes
the procedure-code suggestion list before opening the tooth dropdown.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -526,7 +526,7 @@ class AutomationDDMAClaimSubmit:
|
||||
if listbox_id:
|
||||
option = WebDriverWait(self.driver, 4).until(
|
||||
EC.element_to_be_clickable((By.XPATH,
|
||||
f"//*[@id='{listbox_id}']//*[@role='option'][1]"
|
||||
f"(//*[@id='{listbox_id}']//*[@role='option' or self::li])[1]"
|
||||
))
|
||||
)
|
||||
else:
|
||||
@@ -539,7 +539,8 @@ class AutomationDDMAClaimSubmit:
|
||||
option.click()
|
||||
print(f"[DDMA Claim step4] {label}: selected '{value}'")
|
||||
except TimeoutException:
|
||||
# No dropdown — press Enter or Tab to confirm free text
|
||||
# No dropdown — close any suggestion list and Tab out to confirm free text
|
||||
inp.send_keys(Keys.ESCAPE)
|
||||
inp.send_keys(Keys.TAB)
|
||||
print(f"[DDMA Claim step4] {label}: typed '{value}' (no dropdown)")
|
||||
except Exception as e:
|
||||
@@ -557,6 +558,72 @@ class AutomationDDMAClaimSubmit:
|
||||
except Exception as e:
|
||||
print(f"[DDMA Claim step4] Warning: could not fill {label}: {e}")
|
||||
|
||||
def _close_open_dropdowns(self):
|
||||
"""Close any open autocomplete/listbox (e.g. procedure code suggestions)."""
|
||||
try:
|
||||
self.driver.switch_to.active_element.send_keys(Keys.ESCAPE)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
# Click a neutral spot (the Treatment Form heading area) to blur fields
|
||||
self.driver.execute_script("document.activeElement && document.activeElement.blur();")
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(0.3)
|
||||
|
||||
def _select_tooth(self, idx, tooth):
|
||||
"""Select tooth number in row idx.
|
||||
|
||||
DOM: <input id="ToothNumber{idx}_input" role="combobox" readonly
|
||||
aria-controls="ToothNumber{idx}-ul"> -> <ul id="ToothNumber{idx}-ul"><li>..</li></ul>
|
||||
"""
|
||||
inp = WebDriverWait(self.driver, 8).until(
|
||||
EC.presence_of_element_located((By.ID, f"ToothNumber{idx}_input"))
|
||||
)
|
||||
listbox_id = inp.get_attribute("aria-controls") or f"ToothNumber{idx}-ul"
|
||||
self.driver.execute_script("arguments[0].scrollIntoView({block:'center'});", inp)
|
||||
time.sleep(0.2)
|
||||
|
||||
# Open the dropdown
|
||||
try:
|
||||
inp.click()
|
||||
except Exception:
|
||||
self.driver.execute_script("arguments[0].click();", inp)
|
||||
time.sleep(0.4)
|
||||
if (inp.get_attribute("aria-expanded") or "").lower() != "true":
|
||||
self.driver.execute_script("arguments[0].click();", inp)
|
||||
time.sleep(0.4)
|
||||
|
||||
# Find the option with exact text inside this row's listbox
|
||||
opt_xpath = (
|
||||
f"//*[@id='{listbox_id}']//*[(self::li or @role='option') and normalize-space(.)='{tooth}']"
|
||||
)
|
||||
option = None
|
||||
end = time.time() + 5
|
||||
while time.time() < end and option is None:
|
||||
els = self.driver.find_elements(By.XPATH, opt_xpath)
|
||||
if els:
|
||||
option = els[0]
|
||||
break
|
||||
time.sleep(0.25)
|
||||
if option is None:
|
||||
self._close_open_dropdowns()
|
||||
raise Exception(f"option '{tooth}' not found in #{listbox_id}")
|
||||
|
||||
# List is scrollable — bring the option into view inside it, then click
|
||||
self.driver.execute_script("arguments[0].scrollIntoView({block:'nearest'});", option)
|
||||
time.sleep(0.2)
|
||||
try:
|
||||
option.click()
|
||||
except Exception:
|
||||
self.driver.execute_script("arguments[0].click();", option)
|
||||
time.sleep(0.3)
|
||||
|
||||
val = inp.get_attribute("value") or ""
|
||||
if val.strip() != tooth:
|
||||
print(f"[DDMA Claim step4] tooth[{idx}]: warning, field shows {val!r} after selecting '{tooth}'")
|
||||
return True
|
||||
|
||||
def step4_fill_claim_form(self):
|
||||
"""Fill each treatment row: service date, procedure code, tooth number, surface, amount.
|
||||
|
||||
@@ -624,26 +691,12 @@ class AutomationDDMAClaimSubmit:
|
||||
print(f"[DDMA Claim step4] Could not fill procedure code[{idx}]: {e}")
|
||||
time.sleep(0.2)
|
||||
|
||||
# ── Tooth Number (custom scrollable dropdown, no native <select>) ─
|
||||
# ── Tooth Number (readonly combobox #ToothNumber{idx}_input) ─
|
||||
if tooth:
|
||||
try:
|
||||
tooth_triggers = self.driver.find_elements(By.XPATH, "//span[contains(@class,'filtrable')]")
|
||||
if idx < len(tooth_triggers):
|
||||
trigger = tooth_triggers[idx]
|
||||
self.driver.execute_script("arguments[0].scrollIntoView({block:'center'});", trigger)
|
||||
trigger.click()
|
||||
time.sleep(0.4)
|
||||
option = WebDriverWait(self.driver, 5).until(
|
||||
EC.element_to_be_clickable((By.XPATH,
|
||||
f"//*[@role='option' and normalize-space(.)='{tooth}'] | "
|
||||
f"//li[normalize-space(.)='{tooth}'] | "
|
||||
f"//*[contains(@class,'dropdown')]//*[normalize-space(.)='{tooth}']"
|
||||
))
|
||||
)
|
||||
option.click()
|
||||
print(f"[DDMA Claim step4] tooth[{idx}]: selected '{tooth}'")
|
||||
else:
|
||||
print(f"[DDMA Claim step4] tooth[{idx}]: dropdown trigger not found")
|
||||
self._close_open_dropdowns()
|
||||
self._select_tooth(idx, tooth)
|
||||
print(f"[DDMA Claim step4] tooth[{idx}]: selected '{tooth}'")
|
||||
except Exception as e:
|
||||
print(f"[DDMA Claim step4] Could not fill tooth[{idx}]: {e}")
|
||||
time.sleep(0.2)
|
||||
|
||||
Reference in New Issue
Block a user