diff --git a/CHANGES.rst b/CHANGES.rst index f2c8e78be..067687d7c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,11 @@ Release Notes 1.7 (unreleased) ---------------- +- Fixed ‘NoSuchWindowException' issue. Running keyword 'Select Window' after 'Close Window' + will trigger this issue if locator has prefix 'name=','title=' or 'url='. Also fixed same + issue for keywords 'Get Window Ids', 'Get Window Titles' and 'Get Window Names'. + [divfor] + - Corrected error message in new keyword 'Wait Until Element Is Not Visible' to reflect element being visible instead of not visible. [joepurdy] diff --git a/src/Selenium2Library/locators/windowmanager.py b/src/Selenium2Library/locators/windowmanager.py index c03fac8eb..5740d38a5 100644 --- a/src/Selenium2Library/locators/windowmanager.py +++ b/src/Selenium2Library/locators/windowmanager.py @@ -85,20 +85,28 @@ def _parse_locator(self, locator): def _get_window_infos(self, browser): window_infos = [] - starting_handle = browser.get_current_window_handle() + try: + starting_handle = browser.get_current_window_handle() + except NoSuchWindowException: + starting_handle = None try: for handle in browser.get_window_handles(): browser.switch_to_window(handle) window_infos.append(browser.get_current_window_info()) finally: - browser.switch_to_window(starting_handle) + if starting_handle: + browser.switch_to_window(starting_handle) return window_infos def _select_matching(self, browser, matcher, error): - starting_handle = browser.get_current_window_handle() + try: + starting_handle = browser.get_current_window_handle() + except NoSuchWindowException: + starting_handle = None for handle in browser.get_window_handles(): browser.switch_to_window(handle) if matcher(browser.get_current_window_info()): return - browser.switch_to_window(starting_handle) + if starting_handle: + browser.switch_to_window(starting_handle) raise ValueError(error) diff --git a/test/acceptance/windows.txt b/test/acceptance/windows.txt index 552d3754d..fcee45955 100644 --- a/test/acceptance/windows.txt +++ b/test/acceptance/windows.txt @@ -50,6 +50,17 @@ Get and Set Window Position Should Be Equal ${position_x} ${returned_x} Should Be Equal ${position_y} ${returned_y} +Select Window By Title After Close Window + Cannot Be Executed in IE + Open Popup Window, Select It And Verify myName + Close Popup Window And Select Main Window By Title + +Get Window Titles After Close Window + [Tags] Known Issue - TravisCI + Cannot Be Executed in IE + Open Popup Window, Select It And Verify myName + Close Window + ${titles}= Get Window Titles *Keywords* Open Popup Window, Select It And Verify @@ -66,3 +77,7 @@ Select Main Window And Verify Do Action In Popup Window And Verify Click Link change title Title Should Be Changed + +Close Popup Window And Select Main Window By Title + Close Window + Select Window title=Click link to show a popup window