Last Updated : 11 Jun, 2025
Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provide a simple API to write functional/acceptance tests using Selenium WebDriver. Selenium is a powerful tool for automating browser actions, and its Python bindings provide a simple yet effective way to write tests and interact with web pages.
Selenium WebDriver offers various useful methods to control the session, or in other words, the browser. For example, adding a cookie, pressing the back button, navigating between tabs, etc.
In these articles, we will see the get_window_size driver method in Selenium. get_window_size method gets the width and height of the current window.
get_window_size MethodThe get_window_size method will return the dimensions(width and height) of the current browser in pixels like {'width':****, 'height':****}
. It's useful for tasks like:
Syntax:
driver.get_window_size()
Example:
Now, one can use get_window_size method as a driver method as below -
driver.get("https://www.geeksforgeeks.org/")How to use get_window_size driver method in Selenium Python?
driver.get_window_size()
To demonstrate, get_window_size method of WebDriver in Selenium Python. The example below opens the GeeksforGeeks homepage and prints the current browser window size.
Python
from selenium import webdriver
# Create a new Firefox WebDriver instance
driver = webdriver.Firefox()
# Navigate to the website
driver.get("https://www.geeksforgeeks.org/")
# Retrieve and print the current window size
window_size = driver.get_window_size()
print("Window size:", window_size)
# Close the browser
driver.quit()
Output:
Output of get_window_size driver method (Terminal Window)And here is the browser window output of get_window_size driver method.
Output of get_window_size driver method (Browser window)Note: The actual numbers will depend on your screen resolution and browser window settings.
The get_window_size() method in Selenium Python is a best way to get the current size of your browser window. Which you're testing responsive layouts or automating browser behavior, this is a simple method gives you essential information about your browser's dimensions with proper required details which you want.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4