P
P
PesyCorm2021-01-23 19:26:02
Python
PesyCorm, 2021-01-23 19:26:02

Why doesn't except work?

Hey! I do not quite understand why an tryexception is thrown from the function in the block.

try:
      while True:
  # цикл имеет условие выхода, здесь убрал для сокращения кода
          wait.until(
              EC.presence_of_element_located(
                (By.CLASS_NAME, "demoAuth__item-image")
                )
              ).click()
except AssertionError as e:
      print(e, "Элемент не обнаружен на странице")

I specifically specified the wrong class name to see if it works. exceptAfter waiting, it crashes TimeoutException. I can't figure out why it doesn't go to except?
Thanks for the answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2021-01-23
@PesyCorm

Because the try block only catches the types of exceptions you specify (or all if you don't specify a type at all).
And TimeoutException is not an AssertionError.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question