MinkSelenium2Driver
MinkSelenium2Driver copied to clipboard
Switching windows by name or handle?
Technical limitations
- Selenium 2 can switch windows either by
nameor byhandle(see https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidwindow) - Selenium 3 can switch windows by
handleonly (see https://www.w3.org/TR/webdriver2/#switch-to-window)
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
getWindowNamemethod returns a handle - the
getWindowNamesmethod returns a handles array - the
switchToWindowon Selenium 2 can switch windows by name/handle (see Technical limitations above) - the
switchToWindowon Selenium 3 can switch windows by a handle (see Technical limitations above)
Proposed implementation
See https://github.com/minkphp/MinkSelenium2Driver/pull/384 .
- the
getWindowNamemethod returns a window name (if non-empty) or a handle - the
getWindowNamesmethod returns a window name (if non-empty) or a handle array - the
switchToWindowcan 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
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.
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. But who knows what will be in the future.
I personally like the proposed implementation, because:
- it makes tests pass for Selenium 3;
- the potential problems, described above, are really an edge cases, that might be as common.