Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from selenium.common.exceptions import TimeoutException, NoSuchElementException, ElementNotInteractableException
- # 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'C:\Users\pluca\Desktop\Acte\1CI Petrencu Georgemic.pdf',
- r'C:\Users\pluca\Desktop\Acte\2CertificatatestarefiscalaANAFmic.pdf',
- r'C:\Users\pluca\Desktop\Acte\3CertificatatestarefiscalaCazasumic.pdf',
- r'C:\Users\pluca\Desktop\Acte\4Extrascartefunciaraanexamic.pdf',
- r'C:\Users\pluca\Desktop\Acte\5Certificatatestarefiscala Brailamic.pdf'
- ]
- # 12. Wait for the first file input element and upload the first file
- try:
- file_input_1 = wait.until(EC.presence_of_element_located((By.ID, "document_input_1")))
- file_input_1.send_keys(file_paths[0])
- time.sleep(5)
- except TimeoutException:
- logging.error("Timeout while waiting for file input 1 element.")
- except NoSuchElementException:
- logging.error("File input 1 element not found.")
- except ElementNotInteractableException:
- logging.error("File input 1 element is not interactable.")
- except Exception as e:
- logging.error(f"Error uploading file 1: {str(e)}")
- # 13. Wait for the second file input element and upload the second file
- try:
- file_input_2 = wait.until(EC.presence_of_element_located((By.ID, "document_input_2")))
- file_input_2.send_keys(file_paths[1])
- time.sleep(5)
- except TimeoutException:
- logging.error("Timeout while waiting for file input 2 element.")
- except NoSuchElementException:
- logging.error("File input 2 element not found.")
- except ElementNotInteractableException:
- logging.error("File input 2 element is not interactable.")
- except Exception as e:
- logging.error(f"Error uploading file 2: {str(e)}")
- # Repeat the same error handling pattern for the remaining file uploads
- try:
- file_input_3 = wait.until(EC.presence_of_element_located((By.ID, "document_input_3")))
- file_input_3.send_keys(file_paths[2])
- time.sleep(5)
- except TimeoutException:
- logging.error("Timeout while waiting for file input 3 element.")
- except NoSuchElementException:
- logging.error("File input 3 element not found.")
- except ElementNotInteractableException:
- logging.error("File input 3 element is not interactable.")
- except Exception as e:
- logging.error(f"Error uploading file 3: {str(e)}")
- try:
- file_input_4 = wait.until(EC.presence_of_element_located((By.ID, "document_input_4")))
- file_input_4.send_keys(file_paths[3])
- time.sleep(5)
- except TimeoutException:
- logging.error("Timeout while waiting for file input 4 element.")
- except NoSuchElementException:
- logging.error("File input 4 element not found.")
- except ElementNotInteractableException:
- logging.error("File input 4 element is not interactable.")
- except Exception as e:
- logging.error(f"Error uploading file 4: {str(e)}")
- try:
- file_input_5 = wait.until(EC.presence_of_element_located((By.ID, "document_input_5")))
- file_input_5.send_keys(file_paths[4])
- time.sleep(5)
- except TimeoutException:
- logging.error("Timeout while waiting for file input 5 element.")
- except NoSuchElementException:
- logging.error("File input 5 element not found.")
- except ElementNotInteractableException:
- logging.error("File input 5 element is not interactable.")
- except Exception as e:
- logging.error(f"Error uploading file 5: {str(e)}")
- # Keep the browser open for further actions
- print("Files uploaded with error handling. Please check the log file for any issues.")
- time.sleep(60) # Keep the browser open for further interaction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement