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:
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.
- Using maximize_window()
- Using minimize_window()
- Using set_window_size()
- Using chrome options