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}")
|
print(f"[TuftsSCO Claim step5] Attaching: {abs_path}")
|
||||||
try:
|
try:
|
||||||
add_file_btn = WebDriverWait(self.driver, 10).until(
|
# Don't click the "Add a file" button: it's wired to the hidden
|
||||||
EC.element_to_be_clickable((By.XPATH,
|
# <input type="file"> below, and clicking it triggers the OS-native
|
||||||
"//button[.//span[contains(text(),'Add a file')]] | "
|
# file picker, which WebDriver cannot control. Send the path
|
||||||
"//button[contains(normalize-space(text()),'Add a file')] | "
|
# directly to the input instead (chromedriver allows send_keys on
|
||||||
"//*[contains(text(),'Add a file') and (@role='button' or self::label)]"
|
# file inputs even while display:none).
|
||||||
))
|
file_input = WebDriverWait(self.driver, 10).until(
|
||||||
)
|
|
||||||
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(
|
|
||||||
EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
|
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)
|
file_input.send_keys(abs_path)
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
print(f"[TuftsSCO Claim step5] Attached: {os.path.basename(abs_path)}")
|
print(f"[TuftsSCO Claim step5] Attached: {os.path.basename(abs_path)}")
|
||||||
attached += 1
|
attached += 1
|
||||||
except Exception as e:
|
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)")
|
print(f"[TuftsSCO Claim step5] Attached {attached}/{len(self.claimFiles)} file(s)")
|
||||||
return "SUCCESS"
|
return "SUCCESS"
|
||||||
|
|||||||
Reference in New Issue
Block a user