Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & Test Observability

Change Browser Window Size

Learn how to resize browser window during an Automate session.

Introduction

You can use Selenium commands to resize browser windows in an Automate session. This guide will help you:

  1. Maximize browser window during test runtime
  2. Resize browser window during test runtime

Maximizing browser window size

In any Selenium test - whether run locally or on a Selenium Grid—the browser window is not maximized upon launch. This can keep you from viewing all the elements of the web application you’re testing.

You can programmatically maximize the browser window by adding a Selenium command to your test script.

Supported Browsers and Operating Systems

Capability Description
Supported OS All desktop OS (not supported on mobile devices)
Supported Browser Chrome

If you are using BrowserStack SDK, you can set the following capabilities in the browserstack.yml file:

browserstack.yml

Resizing the browser window

You might have some test scenarios which require you to resize the browser window. To execute this step, you can add a Selenium command to your test script.

Supported Browsers and Operating Systems

Capability Description
Supported OS All desktop OS (not supported on mobile devices)
Supported Browser All (Chrome, Safari, Firefox, IE, Edge) except Safari 10.1

If the browser window is larger than the display screen resolution, elements will appear off-screen. Learn how to change the desktop screen resolution.

The following sample shows you how to resize the browser window to custom dimensions using Selenium:

browserstack.yml

Maximizing browser window size

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

In any Selenium test - whether run locally or on a Selenium Grid—the browser window is not maximized upon launch. This can keep you from viewing all the elements of the web application you’re testing.

You can programmatically maximize the browser window by adding a Selenium command to your test script.

Supported Browsers and Operating Systems

Capability Description
Supported OS All desktop OS (not supported on mobile devices)
Supported Browser All (Chrome, Safari, Firefox, IE, Edge) except Safari 10.1


The following sample shows you how to maximize a browser window:

driver.manage().window().maximize();
driver.manage().window().maximize();
driver.Manage().Window.Maximize();
$web_driver->manage()->window()->maximize();
driver.maximize_window()
driver.manage.window.maximize
$driver->maximize_window();

Resizing the browser window

You might have some test scenarios which require you to resize the browser window. To execute this step, you can add a Selenium command to your test script.

Supported Browsers and Operating Systems

Capability Description
Supported OS All desktop OS (not supported on mobile devices)
Supported Browser All (Chrome, Safari, Firefox, IE, Edge) except Safari 10.1

If the browser window is larger than the display screen resolution, elements will appear off-screen. Learn how to change the desktop screen resolution.

The following sample shows you how to resize the browser window to custom dimensions using Selenium:

/* Requires Java Library
You need to import the library org.openqa.selenium.Dimension into your Java project before implementing the resize action in your script. */

Dimension dimension = new Dimension(1920, 1080);
driver.manage().window().setSize(dimension);
driver.manage.window.resize_to(1920, 1080)
driver.Manage().Window.Size = new Size(x, y);
driver.set_window_size(width, height)
driver.manage().window().setSize(x, y);
/* Requires PHP Class
You need to use the class "Facebook\WebDriver\WebDriverDimension" into your PHP test before implementing the resize action in your code. */

$web_driver->manage()->window()->setSize(new WebDriverDimension(1920, 1080));
$driver->set_window_size(1920, 1080);

Exceptions

Safari 10.1 has a known bug where maximizing or resizing the browser window doesn’t work as expected. Refer to StackOverflow and GitHub pages for more information.

This behavior occurs whether the test is run locally on the workstation or on a Selenium Grid. There’s no workaround for this bug at the moment.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy