Advertisement
NukeVsCity

Untitled

Sep 30th, 2024
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. import logging
  2. from selenium.common.exceptions import TimeoutException, NoSuchElementException, ElementNotInteractableException
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. import time
  7.  
  8. # Configure logging to capture any errors or warnings
  9. logging.basicConfig(filename='selenium_error.log', level=logging.ERROR,
  10.                     format='%(asctime)s - %(levelname)s - %(message)s')
  11.  
  12. # Paths to your files
  13. file_paths = [
  14.     r'D:\Acte\1CI Petrencu Georgemic.pdf',
  15.     r'D:\Acte\2CertificatatestarefiscalaANAFmic.pdf',
  16.     r'D:\Acte\3CertificatatestarefiscalaCazasumic.pdf',
  17.     r'D:\Acte\4Extrascartefunciaraanexamic.pdf',
  18.     r'D:\Acte\5Certificatatestarefiscala Brailamic.pdf'
  19. ]
  20.  
  21. # Wait object
  22. wait = WebDriverWait(driver, 10)
  23.  
  24. # Upload the files
  25. for i, file_path in enumerate(file_paths, start=1):
  26.     try:
  27.         # Locate the file input element and upload the file
  28.         file_input = wait.until(EC.presence_of_element_located((By.ID, f"document_input_{i}")))
  29.         file_input.send_keys(file_path)
  30.         time.sleep(2)  # Let the file load into the input field
  31.        
  32.         # Optional: check if the file is loaded correctly by inspecting its value
  33.         loaded_file = file_input.get_attribute('value')
  34.         print(f"File input {i} now contains: {loaded_file}")
  35.        
  36.         print(f"File {i} uploaded successfully.")
  37.        
  38.     except TimeoutException:
  39.         logging.error(f"Timeout while waiting for file input {i}.")
  40.     except NoSuchElementException:
  41.         logging.error(f"File input {i} not found.")
  42.     except ElementNotInteractableException:
  43.         logging.error(f"File input {i} is not interactable.")
  44.     except Exception as e:
  45.         logging.error(f"Error uploading file {i}: {str(e)}")
  46.  
  47. print("All files processed. Please check for upload completion on the website.")
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement