Breakpoint 2021 - a free, 2-day virtual summit on software quality. Register now.

Change Screen Resolution

Learn how to change the screen resolution for your desktop Selenium tests.

By default, all Selenium tests on desktop run on a screen resolution of 1024x768. You can use our custom resolution capability which lets you specify a different screen resolution for your tests.

Note: Browser window is not maximized upon launch in any Selenium test. Changing the resolution will not maximize browser. See how to maximize and resize the browser window here.
Capability Description Expected values
resolution Set the resolution of your VM before beginning your test A string. Default resolution is 1024x768

Supported resolutions:
Windows (XP, 7): 800x600, 1024x768, 1280x800, 1280x1024, 1366x768, 1440x900, 1680x1050, 1600x1200, 1920x1200, 1920x1080 and 2048x1536

Windows (8, 8.1, 10): 1024x768, 1280x800, 1280x1024, 1366x768, 1440x900, 1680x1050, 1600x1200, 1920x1200, 1920x1080 and 2048x1536

OS X: 1024x768, 1280x960, 1280x1024, 1600x1200 and 1920x1080

For example, refer to the sample of setting resolution to be 1920x1080:

// Change resolution to 1920x1080

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("resolution", "1920x1080");
// Change resolution to 1920x1080

var capabilities = {
 "resolution" : "1920x1080"
}
// Change resolution to 1920x1080

DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("resolution", "1920x1080");
# Change resolution to 1920x1080

$caps = array(
 "resolution" => "1920x1080"
);
# Change resolution to 1920x1080

capabilities = {
 "resolution": "1920x1080"
}
# Change resolution to 1920x1080

caps = Selenium::WebDriver::Remote::Capabilities.new
caps["resolution"] = "1920x1080"
# Allowing all cookies in Safari

my $capabilities = {
  "resolution" => "1920x1080"
}
Note: You can set the screen resolution only at the start of a test. Resolution cannot be changed during test runtime. If you wish to change browser window size during test runtime, then ensure that you have chosen a sufficiently large screen resolution such that page elements do not appear off-screen.

Sample screenshots before and after resolution change

In the sample screenshots shown below, we have run sample tests where we open www.browserstack.com on Chrome 88 browser running in Windows 10 and take a screenshot:

Resolution - 1024x768

Low Screen Resolution screenshot

Resolution - 2048x1536

High Screen Resolution screenshot

Maximize window with resolution - 2048x1536

If we run the maximise window command as given in this page, then your test will run like shown below:

Maximized High Screen Resolution screenshot

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





Talk to automation expert