Skip to content
Advertisement

How to maximize a browser window using the Python bindings for Selenium 2-WebDriver?

I wanted to know how to maximize a browser window using the Python bindings for Selenium 2-WebDriver.

Advertisement

Answer

The trunk version has webdriver.set_window_position(), webdriver.set_window_size() methods:

#!/usr/bin/env python
import time
from contextlib import closing
from selenium.webdriver import Firefox # pip install selenium

with closing(Firefox()) as browser:
    browser.set_window_position(0, 0) #NOTE: 0,0 might fail on some systems
    browser.set_window_size(800, 600)
    time.sleep(2)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement