-2

i am using Python Selenium Chromedriver and i am stuck at a problem. So i want to add different except Expectation to one line, like TimeoutExpectations and ElementClickInterceptedException to one. My current code:

 WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "test2"))).click() WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "test2"))) except TimeoutException: for _ in range(1000): print("Not available... trying again...") driver.refresh() ATC() 

and i want this part look for example like:

except TimeoutException, ElementClickInterceptedException: 

How to get it work?

0

2 Answers 2

1

You can catch multiple exceptions in one line as following:

try: your_code_that_may_rise_exceptions except (SpecificErrorOne, SpecificErrorTwo) as error: handle(error) 

or slightly different syntax:

try: your_code_that_may_rise_exceptions except (SpecificErrorOne, SpecificErrorTwo), e: handle(e) 
Sign up to request clarification or add additional context in comments.

Comments

0

This can be achieved by inserting the following except statement:

except (TimeoutException, ElementClickInterceptedException): 

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.