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 Dimension

From Leeroopedia
Revision as of 11:50, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/SeleniumHQ_Selenium_Dimension.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains WebDriver, Data_Model
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete value object for representing a two-dimensional size (width and height) provided by the Selenium WebDriver library.

Description

Dimension is an immutable value object that encapsulates a width and height as integer values. It is implemented locally within Selenium to avoid depending on external UI libraries such as GWT. The class provides public final fields (width and height) along with corresponding getter methods, and correctly implements equals(), hashCode(), and toString() for value semantics. The toString() method returns a formatted string in the form (width, height).

Usage

Use Dimension when you need to represent or manipulate the size of a browser window, element, or any rectangular area in Selenium. It is commonly used with WebDriver.Window.setSize() and WebDriver.Window.getSize(), as well as with WebElement.getSize().

Code Reference

Source Location

Signature

public class Dimension {
    public final int width;
    public final int height;

    public Dimension(int width, int height)

    public int getWidth()
    public int getHeight()

    @Override public boolean equals(Object o)
    @Override public int hashCode()
    @Override public String toString()
}

Import

import org.openqa.selenium.Dimension;

I/O Contract

Parameter Type Description
width int The horizontal size in pixels
height int The vertical size in pixels
Method Return Type Description
getWidth() int Returns the width value
getHeight() int Returns the height value
equals(Object) boolean Returns true if both width and height match
hashCode() int Hash based on width and height
toString() String Returns "(width, height)" formatted string

Usage Examples

// Create a Dimension representing a 1024x768 browser window
Dimension windowSize = new Dimension(1024, 768);

// Set browser window size
driver.manage().window().setSize(windowSize);

// Retrieve current window size
Dimension currentSize = driver.manage().window().getSize();
int w = currentSize.getWidth();
int h = currentSize.getHeight();

// Retrieve the size of a web element
WebElement element = driver.findElement(By.id("banner"));
Dimension elementSize = element.getSize();
System.out.println("Element size: " + elementSize); // prints "(width, height)"

// Compare two Dimension objects
Dimension a = new Dimension(800, 600);
Dimension b = new Dimension(800, 600);
boolean same = a.equals(b); // true

Related Pages

Page Connections

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