From 72d38d31a24d61dd310041aa6ffb95068ab197cc Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 22 Feb 2019 08:42:53 +1100 Subject: [PATCH] Raise TimeoutException when wait_for_element() fails --- waternsw_grabber/waternsw_grabber.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/waternsw_grabber/waternsw_grabber.py b/waternsw_grabber/waternsw_grabber.py index bd89910..996d922 100644 --- a/waternsw_grabber/waternsw_grabber.py +++ b/waternsw_grabber/waternsw_grabber.py @@ -40,11 +40,19 @@ def has_admin(): def wait_for_element(driver, by, x, timeout=60): - try: - element_present = EC.presence_of_element_located((by, x)) - WebDriverWait(driver, timeout).until(element_present) - except TimeoutException: - print("Timed out waiting for page to load") + """Wait for element on page to load. + + Args: + driver: selenium webdriver object + by: locator strategy (e.g. By.ID) + x: locator string + timeout: maximum wait time (seconds) + + Raises + TimeoutException if element does not load within timeout period + """ + element_present = EC.presence_of_element_located((by, x)) + WebDriverWait(driver, timeout).until(element_present) def get_telemetered_bore(driver, bore_id, start_date, end_date):