How to resize current browser window in Selenium WebDriver with Java?

Ripon Al Wasim picture Ripon Al Wasim · May 21, 2013 · Viewed 23.4k times · Source

I need to resize the browser as 300x400 during executing the Selenium automated tests. How can I resize the browser window in Selenium WebDriver (aka, Selenium 2) with Java?

[Note: It needs to resize the browser window for testing Responsive Web Design (RWD)]

Answer

NilsH picture NilsH · May 21, 2013

You can get a reference to the current window with driver.manage().window(). And the window has a setSize() method, so you could try

Dimension dimension = new Dimension(800, 600);
driver.manage().window().setSize(dimension)