Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] browser windows handling #157

Merged
merged 4 commits into from
Nov 6, 2019
Merged
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions src/widgetastic/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,43 @@ def get_current_location(self):
# useful if it is necessary to recognize current frame
return self.execute_script('return self.location.toString()')

@property
def current_window_handle(self):
"""Returns the current window handle"""
window_handle = self.selenium.current_window_handle
self.logger.debug('current_window_handle -> %r', window_handle)
return window_handle

@property
def window_handles(self):
"""Returns all available window handles"""
window_handles = self.selenium.window_handles
self.logger.debug('window_handles -> %r', window_handles)
return window_handles

def switch_to_window(self, window_name):
"""switches focus to the specified window

Args:
window_name: The name or window handle
"""
self.logger.debug("switch_to_window -> %r", window_name)
self.selenium.switch_to.window(window_name)

def new_window(self, url):
"""Opens the url in new window of the browser.

Args:
url: web address to open in new window
"""
self.logger.info('Opening URL %r in new window', url)
self.selenium.execute_script("window.open('{url}', 'new window')".format(url=url))

def close_window(self):
"""Close current window form browser"""
self.logger.debug("close_window -> %r", self.current_window_handle)
self.selenium.close()


class BrowserParentWrapper(object):
"""A wrapper/proxy class that ensures passing of correct parent locator on elements lookup.
Expand Down