-
Notifications
You must be signed in to change notification settings - Fork 782
Enhance select window #407
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
Changes from all commits
9a80a3c
c2089a4
60a3c26
d51327c
67c62b1
aeeacfa
b66a01b
f51c451
5897311
5cf78a3
7f03d4a
e71c6e9
864cab5
66e2766
1fdd1d8
a0d87d5
c3cdb5a
aa50ade
9ff050e
34d8562
8e39050
2844643
676b207
c12e0f5
971bcaa
2f6a88a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,15 @@ def get_window_titles(self, browser): | |
|
|
||
| def select(self, browser, locator): | ||
| assert browser is not None | ||
|
|
||
| if locator is not None: | ||
| if isinstance(locator, list): | ||
| self._select_by_excludes(browser, locator) | ||
| return | ||
| if locator.lower() == "self" or locator.lower() == "current": | ||
| return | ||
| if locator.lower() == "new" or locator.lower() == "popup": | ||
| self._select_by_last_index(browser) | ||
| return | ||
| (prefix, criteria) = self._parse_locator(locator) | ||
| strategy = self._strategies.get(prefix) | ||
| if strategy is None: | ||
|
|
@@ -53,21 +61,42 @@ def _select_by_url(self, browser, criteria): | |
|
|
||
| def _select_by_default(self, browser, criteria): | ||
| if criteria is None or len(criteria) == 0 or criteria.lower() == "null": | ||
| browser.switch_to_window('') | ||
| handles = browser.get_window_handles() | ||
| browser.switch_to_window(handles[0]) | ||
| return | ||
|
|
||
| try: | ||
| self._select_by_name(browser, criteria) | ||
| return | ||
| except ValueError: pass | ||
|
|
||
| starting_handle = browser.get_current_window_handle() | ||
| except NoSuchWindowException: | ||
| starting_handle = None | ||
| for handle in browser.get_window_handles(): | ||
| browser.switch_to_window(handle) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to only switch to the window when you know that it meets the right criteria? If it's unable to locate the handle you want to switch to, I would think the expected behavior would be to stay on the current handle. |
||
| if criteria == handle: | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a continuation of the above comment, this part would be if criteria == handle:
browser.switch_to_window(handle)
return |
||
| for item in browser.get_current_window_info()[2:4]: | ||
| if item.strip().lower() == criteria.lower(): | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would also call |
||
| if starting_handle: | ||
| browser.switch_to_window(starting_handle) | ||
| raise ValueError("Unable to locate window with handle or name or title or URL '" + criteria + "'") | ||
|
|
||
| def _select_by_last_index(self, browser): | ||
| handles = browser.get_window_handles() | ||
| try: | ||
| self._select_by_title(browser, criteria) | ||
| return | ||
| except ValueError: pass | ||
|
|
||
| raise ValueError("Unable to locate window with name or title '" + criteria + "'") | ||
| if handles[-1] == browser.get_current_window_handle(): | ||
| raise AssertionError("No new window at last index. Please use '@{ex}= | List Windows' + new window trigger + 'Select Window | ${ex}' to find it.") | ||
| except IndexError: | ||
| raise AssertionError("No window found") | ||
| except NoSuchWindowException: | ||
| raise AssertionError("Currently no focus window. where are you making a popup window?") | ||
| browser.switch_to_window(handles[-1]) | ||
|
|
||
| def _select_by_excludes(self, browser, excludes): | ||
| for handle in browser.get_window_handles(): | ||
| if handle not in excludes: | ||
| browser.switch_to_window(handle) | ||
| return | ||
| raise ValueError("Unable to locate new window") | ||
|
|
||
| # Private | ||
|
|
||
| def _parse_locator(self, locator): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I might be missing something. If they provide a locator, couldn't this possible return the wrong window?