18 from collections
import namedtuple
20 from selenium.common.exceptions
import (NoSuchWindowException,
28 WindowInfo = namedtuple(
'WindowInfo',
'handle, id, name, title, url')
34 ContextAware.__init__(self, ctx)
45 starting_handle = self.
driverdriverdriver.current_window_handle
46 except NoSuchWindowException:
47 starting_handle =
None
54 self.
driverdriverdriver.switch_to.window(starting_handle)
57 def select(self, locator, timeout=0):
60 return self.
_select_select(locator)
61 except WindowNotFound:
62 if time.time() > timeout:
67 if not is_string(locator):
69 elif locator.upper() ==
'CURRENT':
71 elif locator.upper() ==
'MAIN':
73 elif locator.upper() ==
'NEW':
82 prefix = locator[:index].strip()
84 return prefix, locator[index + 1:].lstrip()
85 return 'default', locator
88 if '=' not in locator:
89 return locator.find(
':')
90 if ':' not in locator:
91 return locator.find(
'=')
92 return min(locator.find(
'='), locator.find(
':'))
96 lambda window_info: window_info.title == title,
97 "Unable to locate window with title '%s'." % title
102 lambda window_info: window_info.name == name,
103 "Unable to locate window with name '%s'." % name
108 lambda window_info: window_info.url == url,
109 "Unable to locate window with URL '%s'." % url
118 starting_handle = self.
driverdriverdriver.current_window_handle
119 except NoSuchWindowException:
120 starting_handle =
None
123 if criteria == handle:
129 self.
driverdriverdriver.switch_to.window(starting_handle)
130 raise WindowNotFound(
"No window matching handle, name, title or URL "
131 "'%s' found." % criteria)
135 if handles[-1] == self.
driverdriverdriver.current_window_handle:
137 'the current window.')
142 if handle
not in excludes:
150 starting_handle = self.
driverdriverdriver.current_window_handle
151 except NoSuchWindowException:
152 starting_handle =
None
158 self.
driverdriverdriver.switch_to.window(starting_handle)
164 "return [ window.id, window.name ];")
165 except WebDriverException:
170 id
if id
is not None else 'undefined',
def _parse_locator(self, locator)
def _select_main_window(self)
def _select_matching(self, matcher, error)
def _select_by_url(self, url)
def get_window_infos(self)
def _select_by_last_index(self)
def _get_current_window_info(self)
def _select(self, locator)
def _get_locator_separator_index(self, locator)
def __init__(self, ctx)
Base class exposing attributes from the common context.
def select(self, locator, timeout=0)
def _select_by_name(self, name)
def _select_by_excludes(self, excludes)
def _select_by_title(self, title)
def _select_by_default(self, criteria)