Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium Colors

From Leeroopedia
Knowledge Sources
Domains WebDriver, Support, CSS
Last Updated 2026-02-12 00:00 GMT

Overview

The Colors enum provides a comprehensive catalog of named CSS color constants as defined by the W3C CSS Color specification, each mapping to a corresponding Color instance.

Description

Colors is a Java enum containing 148 named color constants from the W3C HTML4/CSS3 color specification, plus TRANSPARENT. Each enum member holds a pre-constructed Color object with the correct RGBA values. The enum provides a single method, getColorValue(), that returns the associated Color instance. This enum is also used internally by the Color.fromString() method's NamedColorConverter to resolve named color strings.

Usage

Use Colors to look up well-known CSS color values by name for assertions or comparisons in tests. It is particularly useful when verifying that CSS properties return expected color values.

Code Reference

Source Location

Signature

public enum Colors {
    TRANSPARENT, ALICEBLUE, ANTIQUEWHITE, AQUA, AQUAMARINE, AZURE,
    BEIGE, BISQUE, BLACK, BLANCHEDALMOND, BLUE, BLUEVIOLET, BROWN, BURLYWOOD,
    CADETBLUE, CHARTREUSE, CHOCOLATE, CORAL, CORNFLOWERBLUE, CORNSILK, CRIMSON, CYAN,
    DARKBLUE, DARKCYAN, DARKGOLDENROD, DARKGRAY, DARKGREEN, DARKGREY, DARKKHAKI,
    DARKMAGENTA, DARKOLIVEGREEN, DARKORANGE, DARKORCHID, DARKRED, DARKSALMON,
    DARKSEAGREEN, DARKSLATEBLUE, DARKSLATEGRAY, DARKSLATEGREY, DARKTURQUOISE, DARKVIOLET,
    DEEPPINK, DEEPSKYBLUE, DIMGRAY, DIMGREY, DODGERBLUE,
    FIREBRICK, FLORALWHITE, FORESTGREEN, FUCHSIA,
    GAINSBORO, GHOSTWHITE, GOLD, GOLDENROD, GRAY, GREY, GREEN, GREENYELLOW,
    HONEYDEW, HOTPINK,
    INDIANRED, INDIGO, IVORY,
    KHAKI,
    LAVENDER, LAVENDERBLUSH, LAWNGREEN, LEMONCHIFFON, LIGHTBLUE, LIGHTCORAL, LIGHTCYAN,
    LIGHTGOLDENRODYELLOW, LIGHTGRAY, LIGHTGREEN, LIGHTGREY, LIGHTPINK, LIGHTSALMON,
    LIGHTSEAGREEN, LIGHTSKYBLUE, LIGHTSLATEGRAY, LIGHTSLATEGREY, LIGHTSTEELBLUE, LIGHTYELLOW,
    LIME, LIMEGREEN, LINEN,
    MAGENTA, MAROON, MEDIUMAQUAMARINE, MEDIUMBLUE, MEDIUMORCHID, MEDIUMPURPLE,
    MEDIUMSEAGREEN, MEDIUMSLATEBLUE, MEDIUMSPRINGGREEN, MEDIUMTURQUOISE, MEDIUMVIOLETRED,
    MIDNIGHTBLUE, MINTCREAM, MISTYROSE, MOCCASIN,
    NAVAJOWHITE, NAVY,
    OLDLACE, OLIVE, OLIVEDRAB, ORANGE, ORANGERED, ORCHID,
    PALEGOLDENROD, PALEGREEN, PALETURQUOISE, PALEVIOLETRED, PAPAYAWHIP, PEACHPUFF, PERU, PINK, PLUM, POWDERBLUE, PURPLE,
    REBECCAPURPLE, RED, ROSYBROWN, ROYALBLUE,
    SADDLEBROWN, SALMON, SANDYBROWN, SEAGREEN, SEASHELL, SIENNA, SILVER, SKYBLUE,
    SLATEBLUE, SLATEGRAY, SLATEGREY, SNOW, SPRINGGREEN, STEELBLUE,
    TAN, TEAL, THISTLE, TOMATO, TURQUOISE,
    VIOLET,
    WHEAT, WHITE, WHITESMOKE,
    YELLOW, YELLOWGREEN;

    public Color getColorValue();
}

Import

import org.openqa.selenium.support.Colors;

I/O Contract

Method

Method Returns Description
getColorValue() Color Returns the Color object with the RGBA values for this named color

Selected Color Values

Constant RGB Values Alpha
TRANSPARENT (0, 0, 0) 0.0
BLACK (0, 0, 0) 1.0
WHITE (255, 255, 255) 1.0
RED (255, 0, 0) 1.0
GREEN (0, 128, 0) 1.0
BLUE (0, 0, 255) 1.0
YELLOW (255, 255, 0) 1.0
CYAN (0, 255, 255) 1.0
MAGENTA (255, 0, 255) 1.0

Usage Examples

// Get a named color's Color object
Color red = Colors.RED.getColorValue();
String rgbaRed = red.asRgba();  // "rgba(255, 0, 0, 1)"

// Use for assertions in tests
String bgColor = element.getCssValue("background-color");
Color actualColor = Color.fromString(bgColor);
assertEquals(Colors.BLUE.getColorValue(), actualColor);

// Access specific color properties
Color transparent = Colors.TRANSPARENT.getColorValue();
System.out.println(transparent.asRgba());  // "rgba(0, 0, 0, 0)"

// Compare CSS output with named constants
Color expected = Colors.CORNFLOWERBLUE.getColorValue();
Color actual = Color.fromString("rgb(100, 149, 237)");
assertEquals(expected, actual);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment