Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99410

Selenium work around 'TimeoutException' is not defined?

$
0
0

I want to work around the TimeOutException in Python Selenium.

This happens:

1.) Open Browser, Call URL
2.) Trying to find Element
2.1) Works sometimes
2.2) Works not sometimes and throws TimeoutException
3.) Should look for other elements

I can never reach step 3.) after we have hit the exception in 2.2) and try/catch does not work.

After step 3.) there are many other steps. How can I let the program flow around this timeout. It is timeouting when the element is not there.

Code

    def getByClass(InputElement, driver):
        getByClass = WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, InputElement)))
        return getByClass

    try:
        element = Dom.getByClass('test-class', driver).text
    except TimeoutException:
        element = 'element not found'
    print(element)

Result

    except TimeoutException:
    NameError: name 'TimeoutException' is not defined

Viewing all articles
Browse latest Browse all 99410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>