{"record":{"id":"a794de1a3821e35f","repo":"SeleniumHQ/selenium","slug":"valid-types-are-tab-and-window-received-type","errorCode":null,"errorMessage":"Valid types are :tab and :window, received: #{type.inspect}","messagePattern":"Valid types are :tab and :window, received: #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/target_locator.rb","lineNumber":55,"sourceCode":"      end\n\n      #\n      # switch to the parent frame\n      #\n\n      def parent_frame\n        @bridge.switch_to_parent_frame\n      end\n\n      #\n      # Switch to a new top-level browsing context\n      #\n      # @param type either :tab or :window\n      #\n\n      # steep:ignore:start\n      def new_window(type = :window)\n        raise ArgumentError, \"Valid types are :tab and :window, received: #{type.inspect}\" unless %i[window\n                                                                                                     tab].include?(type)\n\n        handle = @bridge.new_window(type)['handle']\n\n        if block_given?\n          execute_and_close = proc do\n            yield(self)\n            begin\n              @bridge.close\n            rescue Error::NoSuchWindowError\n              # window already closed\n            end\n          end\n          window(handle, &execute_and_close)\n        else\n          window(handle)\n        end\n      end","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/target_locator.rb#L37-L73","documentation":"Raised by TargetLocator#new_window when the type argument is not one of :window or :tab. These are the only two valid new-window types per the W3C WebDriver specification. The check uses include? on [:window, :tab], so strings, integers, or other symbols all fail.","triggerScenarios":"Calling driver.switch_to.new_window(:popup). Calling driver.switch_to.new_window('window') with a string. Calling driver.switch_to.new_window(:Window) (capitalized). Passing a variable that is nil or an unexpected symbol.","commonSituations":"Using a non-standard window type name. Passing a string from config instead of a symbol. Case sensitivity mistakes (:Window vs :window). Expecting :popup or :new to work.","solutions":["Pass :window or :tab exactly (lowercase symbols).","If accepting type from config/user input, normalize it: type.to_sym and validate against [:window, :tab]."],"exampleFix":"// before\nhandle = driver.switch_to.new_window(:popup)  # invalid\nhandle = driver.switch_to.new_window('window')   # string, not symbol\n\n// after\nhandle = driver.switch_to.new_window(:window)\nhandle = driver.switch_to.new_window(:tab)","handlingStrategy":"type-guard","validationCode":"VALID_WINDOW_TYPES = %i[window tab].freeze\n\ndef safe_new_window(driver, type = :window)\n  type = type.to_sym\n  raise ArgumentError, \"Invalid window type: #{type}. Use :window or :tab.\" unless VALID_WINDOW_TYPES.include?(type)\n  driver.switch_to.new_window(type)\nend","typeGuard":"def valid_window_type?(type)\n  %i[window tab].include?(type.to_sym)\nend","tryCatchPattern":"begin\n  handle = driver.switch_to.new_window(type)\nrescue ArgumentError => e\n  raise unless e.message.include?('Valid types are')\n  raise ArgumentError, \"new_window type must be :window or :tab, got #{type.inspect}\"\nend","preventionTips":["Always pass the symbol :window or :tab explicitly.","If type comes from config, normalize with .to_sym and validate against [:window, :tab].","Default to :window if unsure — it's the more widely supported option."],"tags":["window","new-window","argument-error","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}