fix: Tufts SCO claim file attach — send_keys directly, skip button click
Clicking "Add a file" triggers input.click() which opens the OS-native file picker that WebDriver can't control, causing send_keys on the underlying input to fail with a message-less exception. The input is already present in the DOM (display:none) so send_keys can target it directly without the click.
This commit is contained in:
@@ -752,27 +752,20 @@ class AutomationTuftsSCOClaimSubmit:
|
||||
|
||||
print(f"[TuftsSCO Claim step5] Attaching: {abs_path}")
|
||||
try:
|
||||
add_file_btn = WebDriverWait(self.driver, 10).until(
|
||||
EC.element_to_be_clickable((By.XPATH,
|
||||
"//button[.//span[contains(text(),'Add a file')]] | "
|
||||
"//button[contains(normalize-space(text()),'Add a file')] | "
|
||||
"//*[contains(text(),'Add a file') and (@role='button' or self::label)]"
|
||||
))
|
||||
)
|
||||
self.driver.execute_script("arguments[0].scrollIntoView({block:'center'});", add_file_btn)
|
||||
ActionChains(self.driver).move_to_element(add_file_btn).click().perform()
|
||||
time.sleep(1)
|
||||
|
||||
file_input = WebDriverWait(self.driver, 8).until(
|
||||
# Don't click the "Add a file" button: it's wired to the hidden
|
||||
# <input type="file"> below, and clicking it triggers the OS-native
|
||||
# file picker, which WebDriver cannot control. Send the path
|
||||
# directly to the input instead (chromedriver allows send_keys on
|
||||
# file inputs even while display:none).
|
||||
file_input = WebDriverWait(self.driver, 10).until(
|
||||
EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
|
||||
)
|
||||
self.driver.execute_script("arguments[0].style.display='block';", file_input)
|
||||
file_input.send_keys(abs_path)
|
||||
time.sleep(1.5)
|
||||
print(f"[TuftsSCO Claim step5] Attached: {os.path.basename(abs_path)}")
|
||||
attached += 1
|
||||
except Exception as e:
|
||||
print(f"[TuftsSCO Claim step5] Could not attach {abs_path}: {e}")
|
||||
print(f"[TuftsSCO Claim step5] Could not attach {abs_path}: {type(e).__name__}: {e}")
|
||||
|
||||
print(f"[TuftsSCO Claim step5] Attached {attached}/{len(self.claimFiles)} file(s)")
|
||||
return "SUCCESS"
|
||||
|
||||
Reference in New Issue
Block a user