D
D
Dmitry Laptiev2019-06-19 14:45:03
Python
Dmitry Laptiev, 2019-06-19 14:45:03

How to catch Selenium webdriver TimeoutException?

def get_clickable_element(driver, locator_strategy, locator, inactivity_sign, delay=60, logging=True):
    try:
        wait_for_page_inactivity(driver, inactivity_sign)
        WebDriverWait(driver, delay).until(EC.element_to_be_clickable((locator_strategy, locator)))
        element = driver.find_element(locator_strategy, locator)
        return element
    except TimeoutException as err:
        if logging:
            print("Элемент c " + locator + " не стал активен в течение " + str(delay) + " сек.")
            print(err)
        raise

I can't catch this exp, any ideas?
I get a falling test in response
File "myPath", line 39, in get_clickable_element
    WebDriverWait(driver, delay).until(EC.element_to_be_clickable((locator_strategy, locator)))
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2019-06-19
@ScriptKiddo

from selenium.common.exceptions import TimeoutException
...
except TimeoutException:
    ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question