We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Control browser window size and position for responsive testing.
Testing responsive layouts requires controlling the browser window size. Selenium lets you programmatically set dimensions and position to simulate different devices or screen resolutions.
maximize(): Fills available screen space.setSize(width, height): Sets exact dimensions.getSize(): Returns current window dimensions.setPosition(x, y): Moves window to coordinates.getPosition(): Returns current position.Current Browser Size
Resize your browser window to see values update!
Selenium can set these dimensions programmatically for responsive testing.
12345678910111213// Maximize the window
driver.manage().window().maximize();
// Set to a specific size (e.g., Tablet)
driver.manage().window().setSize(new Dimension(768, 1024));
// Move window to top-left corner
driver.manage().window().setPosition(new Point(0, 0));
// Set to Mobile size
driver.manage().window().setSize(new Dimension(375, 667));
driver.quit();Always set a fixed window size before taking screenshots to ensure they are consistent across different test runs and machines.
Create reusable helper methods like setMobileView() or setDesktopView() to simplify viewport changes in your tests.
Window positioning commands may not work in headless mode. Focus on sizing for CI/CD environments.