diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index 7b26ab04b..0c03d4dc6 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -324,9 +324,11 @@ def new_window(browser, selector=None): """ initial_window_handles = browser.window_handles yield - new_window_handle = next(window for window in browser.window_handles - if window not in initial_window_handles) - browser.switch_to.window(new_window_handle) + new_window_handles = [window for window in browser.window_handles + if window not in initial_window_handles] + if not new_window_handles: + raise Exception("No new windows opened during context") + browser.switch_to.window(new_window_handles[0]) if selector is not None: wait_for_selector(browser, selector)