SeleniumHQ/selenium · error · ArgumentError
expected #{rectangle.inspect}:#{rectangle.class} to respond
Error message
expected #{rectangle.inspect}:#{rectangle.class} to respond to #x, #y, #width, and #height What it means
Raised by Window#rect= (ArgumentError) when the rectangle argument does not respond to all of x, y, width, and height. Validation iterates %w[x y width height] through respond_to? before delegating to bridge.set_window_rect.
Source
Thrown at rb/lib/selenium/webdriver/common/window.rb:89
#
# Get the position of the current window.
#
# @return [Selenium::WebDriver::Point] The position.
#
def position
@bridge.window_position
end
#
# Sets the current window rect to the given point and position.
#
# @param [Selenium::WebDriver::Rectangle, #x, #y, #width, #height] rectangle The new rect.
#
def rect=(rectangle)
unless %w[x y width height].all? { |val| rectangle.respond_to? val }
raise ArgumentError, "expected #{rectangle.inspect}:#{rectangle.class} " \
'to respond to #x, #y, #width, and #height'
end
@bridge.set_window_rect(x: rectangle.x,
y: rectangle.y,
width: rectangle.width,
height: rectangle.height)
end
#
# Get the rect of the current window.
#
# @return [Selenium::WebDriver::Rectangle] The rectangle.
#
def rect
@bridge.window_rect
endView on GitHub (pinned to aa36b38e69)
Solutions
- Pass Selenium::WebDriver::Rectangle.new(x, y, width, height).
- If you only have partial data, fill the missing fields (e.g. fetch current rect first and merge).
- Avoid passing Hashes or Arrays; convert them into a Rectangle (or duck-typed object with all four accessors).
Example fix
// before
driver.manage.window.rect = {x: 0, y: 0, width: 800, height: 600}
// after
driver.manage.window.rect = Selenium::WebDriver::Rectangle.new(0, 0, 800, 600) Defensive patterns
Strategy: type-guard
Validate before calling
def rectangle_like?(obj)
%w[x y width height].all? { |m| obj.respond_to?(m) }
end
raise ArgumentError, 'invalid rectangle' unless rectangle_like?(rect)
driver.manage.window.rect = rect Type guard
def rectangle_like?(obj)
%w[x y width height].all? { |m| obj.respond_to?(m) }
end Prevention
- Build Selenium::WebDriver::Rectangle.new(x, y, w, h) instead of hashes/arrays.
- Don't reuse a Dimension or Point where a full Rectangle is required.
- Validate all four accessors are present before assigning.
When it happens
Trigger: Passing a Dimension (has width/height only), a Point (x/y only), a hash, an array, or a partial struct to driver.manage.window.rect =.
Common situations: Reusing a Dimension or Point object where a full Rectangle is required; passing a Hash with symbol keys (hashes don't respond to x/y/width/height as methods); constructing rects from JSON without wrapping in a Rectangle.
Related errors
- expected #{dimension.inspect}:#{dimension.class} to respond
- expected #{point.inspect}:#{point.class} to respond to #x an
- Valid types are :tab and :window, received: #{type.inspect}
- incompatible proxy type #{type.inspect} (already set to #{@t
- cannot find element by #{how.inspect}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/7661e9914a10614c.
Report an issue: GitHub.