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

Switching windows by name or handle? #868

Open
aik099 opened this issue Feb 26, 2024 · 2 comments
Open

Switching windows by name or handle? #868

aik099 opened this issue Feb 26, 2024 · 2 comments

Comments

@aik099
Copy link
Member

aik099 commented Feb 26, 2024

Technical limitations

Switching windows by a handle

  • the Selenium server provides a handle for the currently focused window
  • the Selenium server provides a handle for all opened windows without the need to focus each of them upfront
  • using a handle is supported for Selenium 2 and Selenium 3
  • providing an empty window name will switch to the first opened window in Selenium 2 only

Switching windows by a name

  • the Selenium server can only return the name for the currently focused window
  • there can be several windows with an empty (non-unique) name
  • no way to switch to the first opened window

Current implementation

  • the getWindowName method returns a handle
  • the getWindowNames method returns a handles array
  • the switchToWindow on Selenium 2 can switch windows by name/handle (see Technical limitations above)
  • the switchToWindow on Selenium 3 can switch windows by a handle only (see Technical limitations above)

Proposed implementation

See minkphp/MinkSelenium2Driver#384 .

  • the getWindowName method returns a window name (if non-empty) or a handle
  • the getWindowNames method returns a window name (if non-empty) or a handle array
  • the switchToWindow can switch windows by a name/handle, but needs to iterate/focus over each window to determine the handle by its name

The downside of the proposed implementation

  1. All windows need to be iterated to retrieve their name, which:
  • can be slow when lots of windows are opened (these websites exist?);
  • when the website has a JavaScript code that closes a window upon focus loss, then iteration can be very bad.
  1. When the window is renamed after opening, then window name obtained by the getWindowName or getWindowNames would produce NoSuchWindow exception, when given to the switchToWindow method

Comments from contributors

In the https://github.com/minkphp/MinkSelenium2Driver/pull/384/files#r1501886088 @uuf6429 proposed to replace window name support with window handle support Mink-wise. Considering, that Selenium-based drivers are the only ones that support window operations now.

In the https://github.com/minkphp/MinkSelenium2Driver/pull/384/files#r1501840465 @mvorisek explained window handle workflow like this:

  1. user opens a window
  2. user store the handle
  3. user uses the handle to switch to that window

I personally like the proposed implementation, because:

  • it makes tests pass for Selenium 3 (it can't switch windows by a name);
  • the potential problems, described above, are really an edge cases, that might be as common.
@stof
Copy link
Member

stof commented Mar 12, 2024

Please keep any discussion about the changing the Mink API in the main Mink repo rather than in drivers please.

@aik099 aik099 transferred this issue from minkphp/MinkSelenium2Driver Mar 12, 2024
@aik099
Copy link
Member Author

aik099 commented Mar 12, 2024

Please keep any discussion about the changing the Mink API in the main Mink repo rather than in drivers please.

Understood. Moved the issue to the main repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants