from selenium.common.exceptions import NoSuchElementException import time import logging import sys, traceback import os from pathlib import Path class Validation: def __init__(self): self.logger = logging.getLogger(__name__) def validate_element_by_id(self, browser, id): self.logger.debug( "Buscando elemento: " + id) ready = False while (not ready): try: browser.find_element_by_id(id) self.logger.debug("El elmento con id {0} esta listo".format(id)) ready = True except: self.logger.debug("El elmento con id {0} no esta listo".format(id)) ready = False time.sleep(0.25) return ready def validate_element_by_tag_name(self, browser, tag): self.logger.debug( "Buscando elemento: " + tag) ready = False while (not ready): try: browser.find_element_by_tag_name(tag) self.logger.debug("El elmento con tag name {0} esta listo".format(tag)) ready = True except: self.logger.debug("El elmento con tag name {0} no esta listo".format(tag)) ready = False time.sleep(0.25) return ready def validate_element_not_present(self, browser, id): self.logger.debug("Buscando elemento: " + id) ready = False while not ready: try: browser.find_element_by_id(id) self.logger.debug("El elmento con id {0} esta presente".format(id)) ready = False except NoSuchElementException: self.logger.debug("El elmento con id {0} no esta presente".format(id)) ready = True time.sleep(0.25) return ready def check_element_by_id(self, driver, id): try: driver.find_element_by_id(id) except NoSuchElementException: return False return True def validate_download(self, filename): self.logger.debug( "Se descargara el archivo: " + filename.split("\\")[-1]) my_file = Path(filename) cont = 0 #Controla la cantidad de intentos para descargar el archivo result=False listo = False while (not listo): try: if my_file.exists(): self.logger.debug("Archivo descargado.!") listo = True result=True else: self.logger.debug("Descargando ...") listo = False except: self.logger.debug("Descargando ...") listo = False traceback.print_exc(file=sys.stdout) if cont == 120: self.logger.debug("Se agoto el tiempo de espera para validar la descargar.") listo = True result=False cont = cont+1 time.sleep(0.5) return result