Advertisement
NukeVsCity

Untitled

Sep 30th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 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'C:\Users\pluca\Desktop\Acte\1CI Petrencu Georgemic.pdf',
  15.     r'C:\Users\pluca\Desktop\Acte\2CertificatatestarefiscalaANAFmic.pdf',
  16.     r'C:\Users\pluca\Desktop\Acte\3CertificatatestarefiscalaCazasumic.pdf',
  17.     r'C:\Users\pluca\Desktop\Acte\4Extrascartefunciaraanexamic.pdf',
  18.     r'C:\Users\pluca\Desktop\Acte\5Certificatatestarefiscala Brailamic.pdf'
  19. ]
  20.  
  21. # Wait object
  22. wait = WebDriverWait(driver, 10)
  23.  
  24. # Upload the files and click the upload button after each file input
  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
  31.  
  32.         # Locate the upload button and click it
  33.         upload_button = wait.until(EC.element_to_be_clickable((By.ID, f"document_{i}")))
  34.         upload_button.click()
  35.         time.sleep(5)  # Wait for the upload to complete
  36.  
  37.         print(f"File {i} uploaded successfully.")
  38.        
  39.     except TimeoutException:
  40.         logging.error(f"Timeout while waiting for file input {i} or upload button.")
  41.     except NoSuchElementException:
  42.         logging.error(f"File input {i} or upload button not found.")
  43.     except ElementNotInteractableException:
  44.         logging.error(f"File input {i} or upload button is not interactable.")
  45.     except Exception as e:
  46.         logging.error(f"Error uploading file {i}: {str(e)}")
  47.  
  48. print("All files processed. Please check for upload completion on the website.")
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement