-2

I have got this try...except block:

try: browser.find_element('xpath', '/html/body/ul').click() wait = WebDriverWait(browser, 10) wait.until(EC.visibility_of_element_located(('xpath', '/html/body/div[1]/div[3]/span'))) return ' '.join(browser.find_element('id', 'response').text.split('\n')[0].split()[:-1]) except ElementNotInteractableException or NoSuchElementException or TimeoutException: return 'No result' 

Still I do get this exception:

 wait = WebDriverWait(browser, 10) File "C:\...\selenium\webdriver\support\wait.py", line 87, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: 

I have tried handling this exception seperately, which didn't work. So I do not understand how I am supposed to handle it, as the code should just ignore the timeout, since it just means the element wasn't found (which is excpected in ~10% of the time).

0

1 Answer 1

1

An except clause with catch either the single exception or multiple exceptions, depending on what the expression following the keyword except evaluates to.

  1. If it evaluates to a single exception class, it will catch exceptions of that type.

  2. If it evaluates to a tuple, it will catch exceptions of any type contained in the tuple.

The expression ElementNotInteractableException or NoSuchElementException or TimeoutException evaluates to the single type ElementNotInteractableException, not a tuple containing the three exception classes.

You want an explicit tuple:

except (ElementNotInteractableException, NoSuchElementException, TimeoutException): ... 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.