Skip to content

select window handling needs some improvement  #340

Closed

Description

@gjemp

Hi my case is described here:
https://mail.google.com/mail/u/0/#inbox/148413cdf87ee7c9

In short. Select window (or any other keyword that is trying to select window ) will fail if window that is focused will be closed before window focus is changed to other window. Same case will happen with Capture Screenshot keyword where it is not able to find the window and will fail.

My suggestions are:
a) another parameter for select window - to select the main window automatically if the last active window is not open anymore to avoid cases where same action can be fail case / bug.
b) create new select window keyword where a) parameter is used as default action.

Activity

  1. divfor commented on May 10, 2015

    @divfor
    Contributor

    ===from windowmanager.py =======
    def _select_matching(self, browser, matcher, error):
    starting_handle = browser.get_current_window_handle()
    for handle in browser.get_window_handles():
    browser.switch_to_window(handle)
    if matcher(browser.get_current_window_info()):
    return
    browser.switch_to_window(starting_handle)
    raise ValueError(error)

    ======change to======
    def _select_matching(self, browser, matcher, error):
    try:
    starting_handle = browser.get_current_window_handle()
    except NoSuchWindowException:
    starting_handle = None
    pass
    for handle in browser.get_window_handles():
    browser.switch_to_window(handle)
    if matcher(browser.get_current_window_info()):
    return
    if starting_handle is not None:
    browser.switch_to_window(starting_handle)
    raise ValueError(error)

  2. self-assigned this
    on May 10, 2015
  3. just-be-dev commented on May 10, 2015

    @just-be-dev
    Contributor

    @divfor, thanks for narrowing this down more. I'm on vacation, but I'll try to address this tomorrow sometime.

  4. divfor commented on May 11, 2015

    @divfor
    Contributor

    NoSuchWindowException will be received if a test selects window right after a 'close window' call, if name/title prefix was given to select window which will lead to call _select_matching() -> get_current_window_handle().the root cause is that browser.get_current_window_handle() will fail after browser.close(). This reason can be found in '6.4 Close Window' section from http://www.w3.org/TR/webdriver/#defining-window-and-frame

    6.4 Close Window
    The close command closes the window that commands are currently being sent to. If this means that a call to get the list of window handles would return an empty list, then this close command must be the equivalent of calling "quit". That is, if the final window of a session is closed, then the session quits.
    Once the window has closed, future commands must return a status code of no such window until a new window is selected for receiving commands.
    

    so, the fix should pass this exception and skip ' browser.switch_to_window(starting_handle)' if catched:

        def _select_matching(self, browser, matcher, error):
            try:
                starting_handle = browser.get_current_window_handle()
            except NoSuchWindowException: pass
            for handle in browser.get_window_handles():
                browser.switch_to_window(handle)
                if matcher(browser.get_current_window_info()):
                    return
            if starting_handle:
                browser.switch_to_window(starting_handle)
            raise ValueError(error)

    However, other function in the future could suffer same issue from close_window(). Since people often want to return previous window when close a popup window, it would be better to let close_window() to do browser.switch_to_window(browser.get_window_handles()[-1]):

        def close_window(self):
            """Closes currently opened pop-up window."""
            self._current_browser().close()
            handles = self._current_browser().get_window_handles()
            if len(handles) >= 1:
                self._current_browser().switch_to_window(handles[-1])
  5. divfor commented on May 11, 2015

    @divfor
    Contributor

    As for enhancement ‘Select Window’, I have raised a PR #395

  6. aaltat commented on May 23, 2016

    @aaltat
    Contributor

    There has not been activity for this issue for long time and we are planning to close the old issues if they are not anymore valid ones. If you feel that this is still valid issue, could you send an update. If update is not received in a month, we will assume that this is not anymore an issues and we will close this issue.

  7. aaltat commented on Nov 2, 2017

    @aaltat
    Contributor

    We made improvements as part of #968. Please retest with the code in master.

  8. removed their assignment
    on Aug 8, 2018
  9. aaltat commented on Aug 21, 2018

    @aaltat
    Contributor

    Closing due inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions