Skip to content

WebDevHubs

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

How to Set the size of window using Selenium Java?

Posted on July 20, 2025July 20, 2025 By Admin No Comments on How to Set the size of window using Selenium Java?

To set the size of the browser window in Selenium Java, use the setSize() method of the WebDriver.Window interface in conjunction with the Dimension class.

Step-by-step Guide

Import the Dimension class:

import org.openqa.selenium.Dimension;

Set the window size after initializing the WebDriver:

// Example: Set window size to 1024x768 pixels driver.manage().window().setSize(new Dimension(1024, 768));

This code resizes the current browser window to the specified width (1024) and height (768) in pixels.

Example Code

javaimport org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Dimension;

public class SetWindowSizeExample {
    public static void main(String[] args) {
        // Initialize the Chrome driver
        WebDriver driver = new ChromeDriver();

        // Set browser window size to 1024x768
        Dimension size = new Dimension(1024, 768);
        driver.manage().window().setSize(size);

        // Proceed with further actions or close the browser
        driver.quit();
    }
}

Key Points

  • Syntax:
    javadriver.manage().window().setSize(new Dimension(width, height));
    Replace width and height with the desired values in pixels.
  • This method sets the outer window size, not just the viewport.
  • Setting window size is useful for responsive testing and simulating different device screen sizes.

You can adjust the width and height to fit your testing needs.

Selenium Tags:Selenium-Java

Post navigation

Previous Post: How to delete all cookies in Selenium Java?
Next Post: How to Set the Position of Window 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