SeleniumHQ/selenium · error · Error::UnsupportedOperationError
Switch to desired window before getting its size
Error message
Switch to desired window before getting its size
What it means
Raised by Remote::Bridge#window_size (Error::UnsupportedOperationError) when a handle other than :current is passed. The W3C get-window-rect command returns dimensions for the current window only, so reading another window's size requires switching to it first.
Source
Thrown at rb/lib/selenium/webdriver/remote/bridge.rb:247
#
def window_handles
execute :get_window_handles
end
def window_handle
execute :get_window_handle
end
def resize_window(width, height, handle = :current)
raise Error::WebDriverError, 'Switch to desired window before changing its size' unless handle == :current
set_window_rect(width: width, height: height)
end
def window_size(handle = :current)
unless handle == :current
raise Error::UnsupportedOperationError,
'Switch to desired window before getting its size'
end
data = execute :get_window_rect
Dimension.new data['width'], data['height']
end
def minimize_window
execute :minimize_window
end
def maximize_window(handle = :current)
unless handle == :current
raise Error::UnsupportedOperationError,
'Switch to desired window before changing its size'
end
execute :maximize_windowView on GitHub (pinned to aa36b38e69)
Solutions
- Switch to the target window with driver.switch_to.window(handle), then call driver.manage.window.size.
- Drop the explicit handle argument and operate on the current window.
- Loop over handles, switching and querying size one at a time.
Example fix
// before size = bridge.window_size(saved_handle) // after driver.switch_to.window(saved_handle) size = driver.manage.window.size
Defensive patterns
Strategy: validation
Validate before calling
driver.switch_to.window(target_handle) size = driver.manage.window.size
Prevention
- Switch to the target window before reading its size.
- Do not pass explicit handles to window_size.
- Loop switch-then-query when inspecting multiple windows.
When it happens
Trigger: Calling bridge.window_size(some_handle) with an explicit handle; legacy code that queried the size of a non-current window by handle.
Common situations: Multi-window scripts that try to inspect other windows without switching; code migrated from the legacy protocol.
Related errors
- Switch to desired window before changing its size
- Unknown error: ${JSON.stringify(data)}
- Invalid URL: ${aUrl}
- Do not know how to build driver: ${browser}; did you forget
- Invalid PointerInput kind '{kind}'
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/8ad59498ba8de5e9.
Report an issue: GitHub.