SeleniumHQ/selenium · error · ArgumentError

expected #{dimension.inspect}:#{dimension.class} to respond

Error message

expected #{dimension.inspect}:#{dimension.class} to respond to #width and #height

What it means

Raised by Window#size= (ArgumentError) when the dimension argument does not respond to both #width and #height. The setter accepts any duck-typed object exposing those readers (typically Selenium::WebDriver::Dimension) and validates via respond_to? before delegating to bridge.resize_window.

Source

Thrown at rb/lib/selenium/webdriver/common/window.rb:39

  module WebDriver
    class Window
      #
      # @api private
      #

      def initialize(bridge)
        @bridge = bridge
      end

      #
      # Resize the current window to the given dimension.
      #
      # @param [Selenium::WebDriver::Dimension, #width and #height] dimension The new size.
      #

      def size=(dimension)
        unless dimension.respond_to?(:width) && dimension.respond_to?(:height)
          raise ArgumentError, "expected #{dimension.inspect}:#{dimension.class} " \
                               'to respond to #width and #height'
        end

        @bridge.resize_window dimension.width, dimension.height
      end

      #
      # Get the size of the current window.
      #
      # @return [Selenium::WebDriver::Dimension] The size.
      #

      def size
        @bridge.window_size
      end

      #
      # Move the current window to the given position.

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Pass a Selenium::WebDriver::Dimension.new(width, height), or any object with width/height readers.
  2. Prefer the positional helper driver.manage.window.resize_to(width, height) which coerces via Integer() and avoids the duck-type requirement.
  3. If building a custom geometry object, ensure it defines attr_reader :width, :height.

Example fix

// before
driver.manage.window.size = [1024, 768]

// after
driver.manage.window.size = Selenium::WebDriver::Dimension.new(1024, 768)
# or simply
driver.manage.window.resize_to(1024, 768)
Defensive patterns

Strategy: type-guard

Validate before calling

def dimension_like?(obj)
  obj.respond_to?(:width) && obj.respond_to?(:height)
end

raise ArgumentError, 'invalid dimension' unless dimension_like?(dim)
driver.manage.window.size = dim

Type guard

def dimension_like?(obj)
  obj.respond_to?(:width) && obj.respond_to?(:height)
end

Prevention

When it happens

Trigger: Calling driver.manage.window.size = [800, 600] (passing an Array), a hash, a single integer, or nil instead of a Dimension/object with width and height methods.

Common situations: Developers passing a two-element array or a struct lacking the expected accessor names; porting code from another binding whose window-size API takes (width, height) positional args; accidental nil from an uninitialized variable.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/4fd2db99ba9eed52. Report an issue: GitHub.