Skip to content

WebDevHubs

  • Home
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • Java
  • Selenium
  • PHP
  • Python
  • Programs
  • Toggle search form

How to Set the Position of Window in Selenium Java?

Posted on July 20, 2025July 20, 2025 By Admin No Comments on How to Set the Position of Window in Selenium Java?

To set the position of the browser window in Selenium Java, use the setPosition() method from the WebDriver.Window interface. This method moves the browser window to the specified (X, Y) screen coordinates, where (0, 0) is the top-left corner of your screen.

Syntax

import org.openqa.selenium.Point;

// Move window to X=100, Y=200
driver.manage().window().setPosition(new Point(100, 200));
  • The X coordinate sets the horizontal distance from the left edge of the screen.
  • The Y coordinate sets the vertical distance from the top edge of the screen.

Complete Code

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Point;

public class SetWindowPosition {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        
        // Set window position to X=100, Y=200
        driver.manage().window().setPosition(new Point(100, 200));
        
        // Optional: Fetch and print actual window position
        Point position = driver.manage().window().getPosition();
        System.out.println("Window position: X=" + position.getX() + " Y=" + position.getY());
        
        driver.quit();
    }
}

Key Points

  • Use positive coordinates to keep the window visible on-screen. Negative values will shift portions of the window off-screen.
  • This technique is useful when running multiple tests in parallel and wanting to organize browser windows on the screen.
  • You can retrieve the current window position using:
Point currentPosition = driver.manage().window().getPosition(); 
int x = currentPosition.getX(); 
int y = currentPosition.getY();

This approach provides precise control over the on-screen position of your Selenium-controlled browser window.

Selenium Tags:Selenium-Java

Post navigation

Previous Post: How to Set the size of window using Selenium Java?
Next Post: How to Maximize the Window Size in Selenium Java?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • CSS
  • HTML
  • Interview Experience
  • Java
  • JavaScript
  • Lodash
  • PHP
  • Programs
  • Python
  • Selenium
  • Software Testing
  • Web Technologies
  • Web Templates

Recent Posts

  • Java ArrayList trimToSize() Method
  • Java ArrayList toArray() Method
  • Java ArrayList subList() Method
  • Java ArrayList spliterator() Method
  • Java ArrayList sort() Method

Recent Comments

No comments to show.

Important Pages

  • About Us
  • Contact Us
  • Terms of Use
  • Privacy Policy

Web Development

  • HTML
  • CSS
  • JavaScript
  • PHP

Programming Languages

  • Java
  • Python
  • PHP
  • Programs

Others

  • Selenium
  • Lodash
  • Java ArrayList
  • JavaScript Array Methods

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme