SeleniumHQ/selenium · error · Error

Did not know how to convert ${value} into color

Error message

Did not know how to convert ${value} into color

What it means

Thrown by Color.fromString() when the input does not match any supported color format. The static method tries converters for rgb, rgb%, rgba, rgba%, hex6, hex3, hsl, hsla, and named CSS colors in sequence; if none succeed, this error fires with the original value.

Source

Thrown at javascript/selenium-webdriver/lib/color.js:59

   * @returns {Color}
   */
  static fromString(value) {
    const v = String(value)
    for (const conv of [
      Color.#fromRgb,
      Color.#fromRgbPct,
      Color.#fromRgba,
      Color.#fromRgbaPct,
      Color.#fromHex6,
      Color.#fromHex3,
      Color.#fromHsl,
      Color.#fromHsla,
      Color.#fromNamed,
    ]) {
      const c = conv(v)
      if (c) return c
    }
    throw new Error(`Did not know how to convert ${value} into color`)
  }

  /**
   * Sets opacity (alpha channel).
   * @param {number} alpha
   */
  setOpacity(alpha) {
    this.alpha_ = Color.#clamp01(alpha)
  }

  /**
   * @returns {string} e.g. "rgb(255, 0, 0)"
   */
  asRgb() {
    return `rgb(${this.red_}, ${this.green_}, ${this.blue_})`
  }

  /**

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Normalize the color to a supported format (hex #rrggbb or rgb(r,g,b)) before calling fromString().
  2. Trim whitespace and validate the format against a known pattern first.
  3. Use a dedicated CSS color parsing library for modern formats (oklch, color()) and pass the rgb equivalent.
  4. Handle 'transparent' and 'currentColor' as special cases before conversion.

Example fix

// before
Color.fromString('oklch(0.5 0.2 240)')
// after
Color.fromString('#3a7bd5') // convert to hex first
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_COLOR_RE = /^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})|rgb\(|rgba\(|hsl\(|hsla\(|[a-z]+)$/i
function isLikelySupportedColor(value) {
  return typeof value === 'string' && SUPPORTED_COLOR_RE.test(value.trim())
}
if (!isLikelySupportedColor(colorStr)) {
  throw new Error(`Unsupported color format: ${colorStr}. Use hex or rgb().`)
}

Prevention

When it happens

Trigger: Passing a color in an unsupported format such as oklch(), color(display-p3 ...), or device-cmyk(). Passing a malformed string, an empty string, or a string with trailing whitespace/units. Passing a CSS variable reference like var(--color).

Common situations: Modern CSS color formats not yet supported by the parser; reading computed styles that return unexpected formats; typos in hex codes; localized or non-standard color names; 'transparent' or 'currentColor'.

Related errors


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