Skip to content

Commit 7664b8d

Browse files
committed
Merge pull request #394 from divfor/Fix-NoSuchWindowException
add fix for 'No Such Window' error
2 parents dad1218 + fafb992 commit 7664b8d

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Release Notes
33

44
1.7 (unreleased)
55
----------------
6+
- Fixed ‘NoSuchWindowException' issue. Running keyword 'Select Window' after 'Close Window'
7+
will trigger this issue if locator has prefix 'name=','title=' or 'url='. Also fixed same
8+
issue for keywords 'Get Window Ids', 'Get Window Titles' and 'Get Window Names'.
9+
[divfor]
10+
611
- Corrected error message in new keyword 'Wait Until Element Is Not
712
Visible' to reflect element being visible instead of not visible.
813
[joepurdy]

src/Selenium2Library/locators/windowmanager.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,28 @@ 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):
98-
starting_handle = browser.get_current_window_handle()
102+
try:
103+
starting_handle = browser.get_current_window_handle()
104+
except NoSuchWindowException:
105+
starting_handle = None
99106
for handle in browser.get_window_handles():
100107
browser.switch_to_window(handle)
101108
if matcher(browser.get_current_window_info()):
102109
return
103-
browser.switch_to_window(starting_handle)
110+
if starting_handle:
111+
browser.switch_to_window(starting_handle)
104112
raise ValueError(error)

test/acceptance/windows.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ Get and Set Window Position
5050
Should Be Equal ${position_x} ${returned_x}
5151
Should Be Equal ${position_y} ${returned_y}
5252

53+
Select Window By Title After Close Window
54+
Cannot Be Executed in IE
55+
Open Popup Window, Select It And Verify myName
56+
Close Popup Window And Select Main Window By Title
57+
58+
Get Window Titles After Close Window
59+
[Tags] Known Issue - TravisCI
60+
Cannot Be Executed in IE
61+
Open Popup Window, Select It And Verify myName
62+
Close Window
63+
${titles}= Get Window Titles
5364

5465
*Keywords*
5566
Open Popup Window, Select It And Verify
@@ -66,3 +77,7 @@ Select Main Window And Verify
6677
Do Action In Popup Window And Verify
6778
Click Link change title
6879
Title Should Be Changed
80+
81+
Close Popup Window And Select Main Window By Title
82+
Close Window
83+
Select Window title=Click link to show a popup window

0 commit comments

Comments
 (0)