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_window

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Switch to the target window with driver.switch_to.window(handle), then call driver.manage.window.size.
  2. Drop the explicit handle argument and operate on the current window.
  3. 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

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


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/8ad59498ba8de5e9. Report an issue: GitHub.