{"record":{"id":"8ad59498ba8de5e9","repo":"SeleniumHQ/selenium","slug":"switch-to-desired-window-before-getting-its-size","errorCode":null,"errorMessage":"Switch to desired window before getting its size","messagePattern":"Switch to desired window before getting its size","errorType":"exception","errorClass":"Error::UnsupportedOperationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/remote/bridge.rb","lineNumber":247,"sourceCode":"        #\n\n        def window_handles\n          execute :get_window_handles\n        end\n\n        def window_handle\n          execute :get_window_handle\n        end\n\n        def resize_window(width, height, handle = :current)\n          raise Error::WebDriverError, 'Switch to desired window before changing its size' unless handle == :current\n\n          set_window_rect(width: width, height: height)\n        end\n\n        def window_size(handle = :current)\n          unless handle == :current\n            raise Error::UnsupportedOperationError,\n                  'Switch to desired window before getting its size'\n          end\n\n          data = execute :get_window_rect\n          Dimension.new data['width'], data['height']\n        end\n\n        def minimize_window\n          execute :minimize_window\n        end\n\n        def maximize_window(handle = :current)\n          unless handle == :current\n            raise Error::UnsupportedOperationError,\n                  'Switch to desired window before changing its size'\n          end\n\n          execute :maximize_window","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/remote/bridge.rb#L229-L265","documentation":"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.","triggerScenarios":"Calling bridge.window_size(some_handle) with an explicit handle; legacy code that queried the size of a non-current window by handle.","commonSituations":"Multi-window scripts that try to inspect other windows without switching; code migrated from the legacy protocol.","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."],"exampleFix":"// before\nsize = bridge.window_size(saved_handle)\n\n// after\ndriver.switch_to.window(saved_handle)\nsize = driver.manage.window.size","handlingStrategy":"validation","validationCode":"driver.switch_to.window(target_handle)\nsize = driver.manage.window.size","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["window","remote","w3c","bridge"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}