SeleniumHQ/selenium · error · ArgumentError
Valid types are :tab and :window, received: #{type.inspect}
Error message
Valid types are :tab and :window, received: #{type.inspect} What it means
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.
Source
Thrown at rb/lib/selenium/webdriver/common/target_locator.rb:55
end
#
# switch to the parent frame
#
def parent_frame
@bridge.switch_to_parent_frame
end
#
# Switch to a new top-level browsing context
#
# @param type either :tab or :window
#
# steep:ignore:start
def new_window(type = :window)
raise ArgumentError, "Valid types are :tab and :window, received: #{type.inspect}" unless %i[window
tab].include?(type)
handle = @bridge.new_window(type)['handle']
if block_given?
execute_and_close = proc do
yield(self)
begin
@bridge.close
rescue Error::NoSuchWindowError
# window already closed
end
end
window(handle, &execute_and_close)
else
window(handle)
end
endView on GitHub (pinned to aa36b38e69)
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].
Example fix
// before
handle = driver.switch_to.new_window(:popup) # invalid
handle = driver.switch_to.new_window('window') # string, not symbol
// after
handle = driver.switch_to.new_window(:window)
handle = driver.switch_to.new_window(:tab) Defensive patterns
Strategy: type-guard
Validate before calling
VALID_WINDOW_TYPES = %i[window tab].freeze
def safe_new_window(driver, type = :window)
type = type.to_sym
raise ArgumentError, "Invalid window type: #{type}. Use :window or :tab." unless VALID_WINDOW_TYPES.include?(type)
driver.switch_to.new_window(type)
end Type guard
def valid_window_type?(type) %i[window tab].include?(type.to_sym) end
Try / catch
begin
handle = driver.switch_to.new_window(type)
rescue ArgumentError => e
raise unless e.message.include?('Valid types are')
raise ArgumentError, "new_window type must be :window or :tab, got #{type.inspect}"
end Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- incompatible proxy type #{type.inspect} (already set to #{@t
- cannot find element by #{how.inspect}
- cannot find elements by #{how.inspect}
- expected #{arg.inspect}:#{arg.class} to respond to #shift
- expected #{arr.inspect} to have 2 elements
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/a794de1a3821e35f.
Report an issue: GitHub.