Open In App

get_window_size driver method - Selenium Python

Last Updated : 11 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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 Method

The 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:

  • Verify the default size of the window.
  • Testing how a web page adapts to different window sizes.

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/")
driver.get_window_size()

How to use get_window_size driver method in Selenium Python?

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
Output of get_window_size driver method (Terminal Window)

And here is the browser window output of get_window_size driver method.

output-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.
 


Next Article
Practice Tags :

Similar Reads