jeudi 22 avril 2021

Python Selenium try: return string except: return boolean

I have a code similar to this:

def number_of_doors():
   try:
      return WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".number .doors"))).text
   except:
      return False

def number_of_windows():
   try:
      return WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".number .windows"))).text
   except:
      return False

if number_of_doors() == number_of_windows():
   print('Doors and windows matched')
elif number_of_doors() != number_of_windows():
   print('Doors and windows not matched')
elif number_of_doors() is False:
   print('Doors not found')

I've been told that it is a bad practice to have string in the try and boolean in the except? If so what could be a better (correct) solution?

Aucun commentaire:

Enregistrer un commentaire