Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/SeleniumLibrary/locators/windowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,11 @@ def _select_matching(self, matcher, error):

def _get_current_window_info(self):
try:
window_id, name = self.driver.execute_script(
"return [ window.id, window.name ];"
)
identity = self.driver.execute_script("return [ window.id, window.name ];")
except WebDriverException:
# The webdriver implementation doesn't support Javascript so we
# can't get window id or name this way.
window_id = name = None
identity = None
# Firefox may also return null if navigation interrupts the script.
window_id, name = identity if identity is not None else (None, None)
return WindowInfo(
self.driver.current_window_handle,
window_id if window_id is not None else "undefined",
Expand Down
11 changes: 11 additions & 0 deletions utest/test/locators/test_windowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ def test_select_by_url(self):
manager.select("url=http://localhost/page2.html")
assert manager.driver.current_window.name == "win2"

def test_select_by_url_when_window_identity_script_returns_none(self):
manager = WindowManagerWithMockBrowser(
{"name": "win1", "title": "Title 1", "url": "http://localhost/page1.html"},
{"name": "win2", "title": "Title 2", "url": "http://localhost/page2.html"},
)
manager.driver.execute_script = lambda script: None

manager.select("url=http://localhost/page2.html")

assert manager.driver.current_window.name == "win2"

def test_select_by_url_with_multiple_matches(self):
manager = WindowManagerWithMockBrowser(
{"name": "win1", "title": "Title 1", "url": "http://localhost/page1.html"},
Expand Down