SeleniumHQ/selenium · error · Error::UnsupportedOperationError

unsupported format: #{format.inspect}

Error message

unsupported format: #{format.inspect}

What it means

Raised by TakesScreenshot#screenshot_as when the format argument is neither :base64 nor :png. The method uses a case statement on format; only these two symbols are handled. Any other value (a string, an integer, nil, another symbol) falls through to the else branch raising UnsupportedOperationError.

Source

Thrown at rb/lib/selenium/webdriver/common/takes_screenshot.rb:63

      #
      # @param [:base64, :png] format
      # @param [Boolean] full_page allows taking full page screenshots if supported
      # @return String screenshot
      #
      # @api public

      def screenshot_as(format, full_page: false)
        if full_page && !respond_to?(:save_full_page_screenshot)
          raise Error::UnsupportedOperationError, "Full Page Screenshots are not supported for #{inspect}"
        end

        case format
        when :base64
          full_page ? full_screenshot : screenshot
        when :png
          screenshot_as(:base64, full_page: full_page).unpack1('m')
        else
          raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
        end
      end
    end # TakesScreenshot
  end # WebDriver
end # Selenium

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use :png or :base64 as the format argument.
  2. Prefer driver.save_screenshot(path) for file output — it handles the format internally.
  3. If accepting format from user input, validate against [:base64, :png] before calling.

Example fix

// before
screenshot = driver.screenshot_as('png')  # string, not symbol
data = driver.screenshot_as(:jpeg)          # unsupported format

// after
screenshot = driver.screenshot_as(:png)
# or for base64:
screenshot = driver.screenshot_as(:base64)
Defensive patterns

Strategy: validation

Validate before calling

VALID_FORMATS = %i[base64 png].freeze

def screenshot_safe(driver, format)
  format = format.to_sym
  raise ArgumentError, "Unsupported screenshot format: #{format}. Use :base64 or :png." unless VALID_FORMATS.include?(format)
  driver.screenshot_as(format)
end

Type guard

def valid_screenshot_format?(format)
  %i[base64 png].include?(format.to_sym)
end

Try / catch

begin
  data = driver.screenshot_as(format)
rescue Selenium::WebDriver::Error::UnsupportedOperationError => e
  raise unless e.message.include?('unsupported format')
  data = driver.screenshot_as(:png)  # safe default
end

Prevention

When it happens

Trigger: Calling driver.screenshot_as('png') with a string instead of a symbol. Calling driver.screenshot_as(:jpeg) or :jpg (JPEG is not supported; Selenium screenshots are always PNG). Calling driver.screenshot_as(nil) due to a variable that wasn't set.

Common situations: Passing a file extension string like 'png' or 'jpg' instead of the symbol :png. Assuming JPEG output is available. Variable-based format that defaults to nil or a string.

Related errors


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