Maximize WebDriver (Selenium 2) in Python

Maximize WebDriver (Selenium 2) in Python

Ive never used this functionality before, so I tried it out.


This seems to work fine – unless I am using Chrome. Im not sure if this is a defect, as it works flawlessly in IE9 and Firefox.

This is a feature which has yet to be implemented in Chromedriver -= Link to issue =-

edit (8 years later):
Apparently this is working in Chrome on Linux and Windows – so, yay! I havent tested it, but I am optimistic since it has been nearly a decade since the original answer was provided.

Even if this is old, its cool to know that you can always get values from system then set it by hand. This would work on every webdriver you use.

#!/usr/bin/env python
#! -*- coding: utf-8 -*-

import selenium
from selenium import webdriver

import os, sys, time

import wx

print example with maximize_window()
nav = webdriver.Firefox()

print example with fixed set_window_size(1024, 768)
nav = webdriver.Firefox()
nav.set_window_size(1024, 768)

print example grabbing size with wx (wxWidgets)
nav = webdriver.Firefox()
app = wx.App(False) #wx.App(False) # the wx.App object must be created first.
screenxy = wx.GetDisplaySize()  # returns a tuple
nav.set_window_size(screenxy[0], screenxy[1])


Maximize WebDriver (Selenium 2) in Python

There is a really simple way to create a maximized window:

from import Options

chrome_options = Options()
# maximized window

You can also use this library for maximizing the window and more, see the documentation:

Leave a Reply

Your email address will not be published. Required fields are marked *