Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from selenium.common.exceptions import TimeoutException, NoSuchElementException, ElementNotInteractableException
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- import time
- # Configure logging to capture any errors or warnings
- logging.basicConfig(filename='selenium_error.log', level=logging.ERROR,
- format='%(asctime)s - %(levelname)s - %(message)s')
- # Paths to your files
- file_paths = [
- r'D:\Acte\1CI Petrencu Georgemic.pdf',
- r'D:\Acte\2CertificatatestarefiscalaANAFmic.pdf',
- r'D:\Acte\3CertificatatestarefiscalaCazasumic.pdf',
- r'D:\Acte\4Extrascartefunciaraanexamic.pdf',
- r'D:\Acte\5Certificatatestarefiscala Brailamic.pdf'
- ]
- # Wait object
- wait = WebDriverWait(driver, 10)
- # Upload the files
- for i, file_path in enumerate(file_paths, start=1):
- try:
- # Locate the file input element and upload the file
- file_input = wait.until(EC.presence_of_element_located((By.ID, f"document_input_{i}")))
- file_input.send_keys(file_path)
- time.sleep(2) # Let the file load into the input field
- # Optional: check if the file is loaded correctly by inspecting its value
- loaded_file = file_input.get_attribute('value')
- print(f"File input {i} now contains: {loaded_file}")
- print(f"File {i} uploaded successfully.")
- except TimeoutException:
- logging.error(f"Timeout while waiting for file input {i}.")
- except NoSuchElementException:
- logging.error(f"File input {i} not found.")
- except ElementNotInteractableException:
- logging.error(f"File input {i} is not interactable.")
- except Exception as e:
- logging.error(f"Error uploading file {i}: {str(e)}")
- print("All files processed. Please check for upload completion on the website.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement