8

I am trying to use the Firefox driver for Splinter to test some responsive design.

Naturally, this requires me to resize the browser window. I can't find anything at all about browser resizing in the documentation.

How can I do this?

from splinter import Browser
with Browser() as browser:
    # How do I set the browser size?
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
HansBos
  • 83
  • 1
  • 4

1 Answers1

19

Just do this:

browser.driver.set_window_size(640, 480)

The Splinter API doesn't seem to directly support this - or at least not yet. The generic API docs, as well as the docs for each specific browser's driver, currently make no mention of anything related to window size). However, a seemingly undocumented feature is that you're able to access the underlying Selenium webdriver instance of a Splinter webdriver instance through its .driver property:

>>> from splinter import Browser
>>> browser = Browser()
>>> browser
<splinter.driver.webdriver.firefox.WebDriver object at 0x7fac66d93a10>
>>> browser.driver
<selenium.webdriver.firefox.webdriver.WebDriver object at 0x1fbf3d0>

This allows us to use any Selenium features that don't have wrappers in the Splinter API, like resizing the browser with the set_window_size method.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
  • This (browser.driver.set_window_size(640, 480) is working perfectly! Thanks. – HansBos Jan 13 '14 at 15:57
  • 5
    +1 for helping me find the driver under the browser. maximize is what I was looking for and on firefox is browser.driver.maximize_window() – charo Apr 11 '15 at 03:08