Make Selenium Easy

How To Set The Size Of Browser Window In Selenium?


When we launch the browser in Selenium generally maximize the browser. But sometimes we may need to explicitly set the size of the browser window as well.

If you run your scripts in headless mode or on the cloud then maximizing the window browser does not work sometimes and you may get NoSuchElementException. In this case, setting the browser window size explicitly will work.

To test the responsiveness of your application with different sizes of browser windows also requires setting the size of the browser window explicitly.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

Dimension Class

Selenium provides a class named Dimension which can be used to get the current size of the browser window and set the new size of the browser window. Size means the height and width of the browser.

To get the current size of the browser

To set the new size of the browser

Complete Code


Please note default size depends on your screen size.

Please subscribe to my YouTube channel Retarget Common to learn from my video tutorials.

Below are important end to end tutorials for Testers:-

Selenium Tutorials

Rest Assured Tutorials

Postman Tutorials

TestNG Tutorials

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

How To Set The Size Of Browser Window In Selenium?

by Amod Mahajan time to read: 2 min
%d bloggers like this: