Advertisement
NukeVsCity

Fgee

Sep 30th, 2024
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1. import logging
  2. from selenium.common.exceptions import TimeoutException, NoSuchElementException, ElementNotInteractableException
  3.  
  4. # Configure logging to capture any errors or warnings
  5. logging.basicConfig(filename='selenium_error.log', level=logging.ERROR,
  6.                     format='%(asctime)s - %(levelname)s - %(message)s')
  7.  
  8. # Paths to your files
  9. file_paths = [
  10.     r'C:\Users\pluca\Desktop\Acte\1CI Petrencu Georgemic.pdf',
  11.     r'C:\Users\pluca\Desktop\Acte\2CertificatatestarefiscalaANAFmic.pdf',
  12.     r'C:\Users\pluca\Desktop\Acte\3CertificatatestarefiscalaCazasumic.pdf',
  13.     r'C:\Users\pluca\Desktop\Acte\4Extrascartefunciaraanexamic.pdf',
  14.     r'C:\Users\pluca\Desktop\Acte\5Certificatatestarefiscala Brailamic.pdf'
  15. ]
  16.  
  17. # 12. Wait for the first file input element and upload the first file
  18. try:
  19.     file_input_1 = wait.until(EC.presence_of_element_located((By.ID, "document_input_1")))
  20.     file_input_1.send_keys(file_paths[0])
  21.     time.sleep(5)
  22. except TimeoutException:
  23.     logging.error("Timeout while waiting for file input 1 element.")
  24. except NoSuchElementException:
  25.     logging.error("File input 1 element not found.")
  26. except ElementNotInteractableException:
  27.     logging.error("File input 1 element is not interactable.")
  28. except Exception as e:
  29.     logging.error(f"Error uploading file 1: {str(e)}")
  30.  
  31. # 13. Wait for the second file input element and upload the second file
  32. try:
  33.     file_input_2 = wait.until(EC.presence_of_element_located((By.ID, "document_input_2")))
  34.     file_input_2.send_keys(file_paths[1])
  35.     time.sleep(5)
  36. except TimeoutException:
  37.     logging.error("Timeout while waiting for file input 2 element.")
  38. except NoSuchElementException:
  39.     logging.error("File input 2 element not found.")
  40. except ElementNotInteractableException:
  41.     logging.error("File input 2 element is not interactable.")
  42. except Exception as e:
  43.     logging.error(f"Error uploading file 2: {str(e)}")
  44.  
  45. # Repeat the same error handling pattern for the remaining file uploads
  46. try:
  47.     file_input_3 = wait.until(EC.presence_of_element_located((By.ID, "document_input_3")))
  48.     file_input_3.send_keys(file_paths[2])
  49.     time.sleep(5)
  50. except TimeoutException:
  51.     logging.error("Timeout while waiting for file input 3 element.")
  52. except NoSuchElementException:
  53.     logging.error("File input 3 element not found.")
  54. except ElementNotInteractableException:
  55.     logging.error("File input 3 element is not interactable.")
  56. except Exception as e:
  57.     logging.error(f"Error uploading file 3: {str(e)}")
  58.  
  59. try:
  60.     file_input_4 = wait.until(EC.presence_of_element_located((By.ID, "document_input_4")))
  61.     file_input_4.send_keys(file_paths[3])
  62.     time.sleep(5)
  63. except TimeoutException:
  64.     logging.error("Timeout while waiting for file input 4 element.")
  65. except NoSuchElementException:
  66.     logging.error("File input 4 element not found.")
  67. except ElementNotInteractableException:
  68.     logging.error("File input 4 element is not interactable.")
  69. except Exception as e:
  70.     logging.error(f"Error uploading file 4: {str(e)}")
  71.  
  72. try:
  73.     file_input_5 = wait.until(EC.presence_of_element_located((By.ID, "document_input_5")))
  74.     file_input_5.send_keys(file_paths[4])
  75.     time.sleep(5)
  76. except TimeoutException:
  77.     logging.error("Timeout while waiting for file input 5 element.")
  78. except NoSuchElementException:
  79.     logging.error("File input 5 element not found.")
  80. except ElementNotInteractableException:
  81.     logging.error("File input 5 element is not interactable.")
  82. except Exception as e:
  83.     logging.error(f"Error uploading file 5: {str(e)}")
  84.  
  85. # Keep the browser open for further actions
  86. print("Files uploaded with error handling. Please check the log file for any issues.")
  87. time.sleep(60)  # Keep the browser open for further interaction
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement