Skip to content

Commit 1f7bf75

Browse files
committed
Mange exception only and close_window() reversed
Keywords right after keyword 'Close Windwo' will fail due to NoSuchWinowExecption: 1. keyword 'Select Window' with named argument 'name=xxx'/'title=xxx'/'url=xxx', fixed _select_matching() as it calls get_current_window_handle() 2. keyword 'Get Window Ids/Names/Titles', will fail on NoSuchWinowExecption, fixed _get_window_infos() as it calls get_current_window_handle() Also reversed close_window() (not switching to prevoius window)
1 parent 2af7ffb commit 1f7bf75

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/Selenium2Library/keywords/_browsermanagement.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,8 @@ def switch_browser(self, index_or_alias):
212212
# Public, window management
213213

214214
def close_window(self):
215-
"""Closes currently opened pop-up window and switch back to previous window.
216-
It assumes the last opened window is in the last index of window list.
217-
However, as opened windows are list-returned from tree-order in remote end,
218-
please use 'Select Window' if automatic switching does not work as expected.
219-
"""
215+
"""Closes currently opened pop-up window."""
220216
self._current_browser().close()
221-
handles = self._current_browser().get_window_handles()
222-
if len(handles) >= 1:
223-
self._current_browser().switch_to_window(handles[-1])
224217

225218
def get_window_identifiers(self):
226219
"""Returns and logs id attributes of all windows known to the browser."""

src/Selenium2Library/locators/windowmanager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,24 @@ def _parse_locator(self, locator):
8585

8686
def _get_window_infos(self, browser):
8787
window_infos = []
88-
starting_handle = browser.get_current_window_handle()
88+
try:
89+
starting_handle = browser.get_current_window_handle()
90+
except NoSuchWindowException:
91+
starting_handle = None
8992
try:
9093
for handle in browser.get_window_handles():
9194
browser.switch_to_window(handle)
9295
window_infos.append(browser.get_current_window_info())
9396
finally:
94-
browser.switch_to_window(starting_handle)
97+
if starting_handle:
98+
browser.switch_to_window(starting_handle)
9599
return window_infos
96100

97101
def _select_matching(self, browser, matcher, error):
98102
try:
99103
starting_handle = browser.get_current_window_handle()
100-
except NoSuchWindowException: pass
104+
except NoSuchWindowException:
105+
starting_handle = None
101106
for handle in browser.get_window_handles():
102107
browser.switch_to_window(handle)
103108
if matcher(browser.get_current_window_info()):

0 commit comments

Comments
 (0)