How To Resize Browser In Selenium WebDriver

In this tutorial, I will show you how to Resize Browser in Selenium WebDriver. Suppose you have to test the responsive web design of a web application with respect to different devices like desktop, Mobile Phone, and Tab, etc because the requirement is to check how the different elements on the page render when the browser window is resized. Hence by changing the browser size on your desktop you can test the GUI of the application

So here we go and let’s see how to do it.

Resize Browser In Selenium WebDriver

In order to resize the browser window to the required dimensions, we can use the Dimension class to resize the browser window as per our need. If you are using Chrome browser and press the F12 key it will give you the option to toggle between different devices and custom devices as well. For example, in the following screenshot, I have selected the device iPad having dimensions (768,1024).

Resize browser in Selenium webdriver

Let us assume that we have to test the application as per its look and feel on an iPad having the same dimension as discussed above that is (768,1024).

The following example will open Wikipedia and then set the browser window size to (768,1024).


Original Browser Window Dimension: (1050, 708)
Current Browser Window Size is: (768, 788)


Now we have learned how to resize the browser window in Selenium quite easily to any desirable size. Hope you have liked this tutorial.

Recommended Posts

Leave a Reply