{"record":{"id":"50a97d2466aaf582","repo":"SeleniumHQ/selenium","slug":"switch-to-desired-window-before-changing-its-size","errorCode":null,"errorMessage":"Switch to desired window before changing its size","messagePattern":"Switch to desired window before changing its size","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/remote/bridge.rb","lineNumber":240,"sourceCode":"\n        def refresh\n          execute :refresh\n        end\n\n        #\n        # window handling\n        #\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","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/remote/bridge.rb#L222-L258","documentation":"Raised by Remote::Bridge#resize_window (Error::WebDriverError) when a window handle other than the default :current is passed. The W3C WebDriver set-window-rect command always operates on the current window, so Selenium requires the caller to switch to the target window first; passing a specific handle is no longer supported.","triggerScenarios":"Calling bridge.resize_window(width, height, some_handle) with an explicit handle instead of the default :current; legacy code that passed a saved window handle to resize a non-current window.","commonSituations":"Porting code from the legacy JSON-Wire Protocol where resizing a specific handle was allowed; managing multiple windows and trying to resize one without switching to it first.","solutions":["Call driver.switch_to.window(target_handle) before resizing, then call resize without a handle.","Prefer the high-level API driver.manage.window.resize_to(width, height) which operates on the current window.","Remove any explicit handle argument from resize_window calls."],"exampleFix":"// before\nbridge.resize_window(800, 600, saved_handle)\n\n// after\ndriver.switch_to.window(saved_handle)\ndriver.manage.window.resize_to(800, 600)","handlingStrategy":"validation","validationCode":"# Always operate on the current window; switch first when needed\ndriver.switch_to.window(target_handle)\ndriver.manage.window.resize_to(width, height)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass an explicit handle to resize_window; switch to the window first.","Use the high-level driver.manage.window.resize_to(w, h) API.","Treat window handle arguments as removed under the W3C protocol."],"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"}