How to use set_window_size() In Software Testing

The set_window_size() is used to set the size of the browser of the user’s preferred choice. We need to pass the values of width and height to set_window_size().

Syntax:

driver.set_window_size(width, height)

Python3




#Python Program to Implement set_window_size
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
 
# chromedriver path
service_obj = Service('C:\\webdrivers_selenium\\chromedriver.exe')
 
# driver object
driver = webdriver.Chrome(service=service_obj)
 
# opening browser
 
# maximizing browser to the width 1200 and height 1400
driver.set_window_size(500, 1400)
 
# closing browser
driver.close()


Output:

set_window_size()

How to set browser width and height in Selenium WebDriver?

Using Selenium WebDriver, we can set the browser width and height. Various methods are available to set browser width and height. When we run any test, the browser will open in default size. So, if we need to change the size of the browser, we can do it using selenium WebDriver keywords. A few of them are listed below.

  1. Using maximize_window()
  2. Using minimize_window()
  3. Using set_window_size()
  4. Using chrome options

Similar Reads

Using maximize_window():

maximize_window() is one of the methods in the Selenium web driver to set the size of the browser. The function of maximize_window() is to maximize the browser window to full-screen size....

Using minimize_window():

...

Using set_window_size():

minimize_window() is a method in Selenium web driver to minimize the browser window. It will keep the browser in a docked view or taskbar....

Using Chrome options:

...

Contact Us