fix: UnitedDH selenium duplicated first attachment (multi-file input appends on send_keys)

DentalHub's upload input is a multi-file input; chromedriver send_keys
appends to the existing selection instead of replacing it, so the second
iteration re-uploaded the first file (2 attachments became 3). Clear the
input value before each send_keys and skip duplicate filePaths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 00:08:30 -04:00
co-authored by Claude Fable 5
parent efb85d0b92
commit 5044fecb07
2 changed files with 18 additions and 0 deletions
@@ -1096,11 +1096,16 @@ class AutomationUnitedDHClaimSubmit:
print(f"[UnitedDH Claim] step7: Could not click caret (section may already be open): {e}")
attached = 0
seen_paths = set()
for cf in self.claimFiles:
relative_path = cf.get("filePath") or ""
if not relative_path:
print(f"[UnitedDH Claim] step7: Skipping file with no filePath: {cf}")
continue
if relative_path in seen_paths:
print(f"[UnitedDH Claim] step7: Skipping duplicate file: {relative_path}")
continue
seen_paths.add(relative_path)
abs_path = os.path.normpath(os.path.join(_BACKEND_CWD, relative_path.lstrip("/")))
if not os.path.isfile(abs_path):
@@ -1113,6 +1118,10 @@ class AutomationUnitedDHClaimSubmit:
EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
)
self.driver.execute_script("arguments[0].removeAttribute('class');", file_input)
# The input is a multi-file input and chromedriver APPENDS on send_keys,
# so a leftover selection from the previous iteration re-uploads the
# earlier file (2 attachments became 3). Clear it first.
self.driver.execute_script("arguments[0].value = '';", file_input)
file_input.send_keys(abs_path)
WebDriverWait(self.driver, 60).until(
EC.element_to_be_clickable((By.XPATH,
@@ -1035,11 +1035,16 @@ class AutomationUnitedDHPreAuth:
print(f"[UnitedDH PreAuth] step7: Could not click caret (section may already be open): {e}")
attached = 0
seen_paths = set()
for cf in self.claimFiles:
relative_path = cf.get("filePath") or ""
if not relative_path:
print(f"[UnitedDH PreAuth] step7: Skipping file with no filePath: {cf}")
continue
if relative_path in seen_paths:
print(f"[UnitedDH PreAuth] step7: Skipping duplicate file: {relative_path}")
continue
seen_paths.add(relative_path)
abs_path = os.path.normpath(os.path.join(_BACKEND_CWD, relative_path.lstrip("/")))
if not os.path.isfile(abs_path):
@@ -1052,6 +1057,10 @@ class AutomationUnitedDHPreAuth:
EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
)
self.driver.execute_script("arguments[0].removeAttribute('class');", file_input)
# The input is a multi-file input and chromedriver APPENDS on send_keys,
# so a leftover selection from the previous iteration re-uploads the
# earlier file (2 attachments became 3). Clear it first.
self.driver.execute_script("arguments[0].value = '';", file_input)
file_input.send_keys(abs_path)
WebDriverWait(self.driver, 60).until(
EC.element_to_be_clickable((By.XPATH,