Implementation:SeleniumHQ Selenium Point
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Data_Model |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete value object for representing a location in a two-dimensional coordinate space provided by the Selenium WebDriver library.
Description
Point is an immutable value object that encapsulates an x and y coordinate as integer values. It represents a point in a two-dimensional space and is used throughout the Selenium API to describe positions of windows and elements. The class provides public final fields (x and y) along with getter methods, a moveBy() method that returns a new Point offset by the given amounts, and correctly implements equals(), hashCode(), and toString() for value semantics.
Usage
Use Point when you need to represent or manipulate the position of a browser window or web element. It is commonly used with WebDriver.Window.setPosition(), WebDriver.Window.getPosition(), and WebElement.getLocation(). The moveBy() method is useful for computing relative positions.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/Point.java
Signature
public class Point {
public final int x;
public final int y;
public Point(int x, int y)
public int getX()
public int getY()
public Point moveBy(int xOffset, int yOffset)
@Override public boolean equals(Object o)
@Override public int hashCode()
@Override public String toString()
}
Import
import org.openqa.selenium.Point;
I/O Contract
| Parameter | Type | Description |
|---|---|---|
| x | int |
The horizontal coordinate (pixels from left) |
| y | int |
The vertical coordinate (pixels from top) |
| Method | Return Type | Description |
|---|---|---|
getX() |
int |
Returns the x coordinate |
getY() |
int |
Returns the y coordinate |
moveBy(int xOffset, int yOffset) |
Point |
Returns a new Point offset by the given x and y amounts |
equals(Object) |
boolean |
Returns true if both x and y match |
hashCode() |
int |
Hash based on x and y |
toString() |
String |
Returns "(x, y)" formatted string
|
Usage Examples
// Create a Point at coordinates (100, 200)
Point position = new Point(100, 200);
// Set browser window position
driver.manage().window().setPosition(position);
// Retrieve current window position
Point currentPos = driver.manage().window().getPosition();
int x = currentPos.getX();
int y = currentPos.getY();
// Get the location of a web element
WebElement element = driver.findElement(By.id("header"));
Point elementPos = element.getLocation();
System.out.println("Element location: " + elementPos); // prints "(x, y)"
// Compute a new point offset from an existing one
Point original = new Point(50, 75);
Point moved = original.moveBy(10, -20); // new Point(60, 55)
// Compare two Point objects
Point a = new Point(100, 200);
Point b = new Point(100, 200);
boolean same = a.equals(b); // true