Looking for a way to minimize and maximize browser window for IE, Firefox and chrome

7,814 views
Skip to first unread message

Talwinder singh

unread,
Apr 27, 2012, 2:13:27 AM4/27/12
to webdriver

Hi All,

Is there a way to minimize and maximize a browser window using
webdriver or webdriverbackedselenium ?


It will be of great help for my test framework.

Thanks in Advance.

Regards
Talwinder

Ranjith Manne

unread,
Apr 27, 2012, 3:04:44 AM4/27/12
to webd...@googlegroups.com

Method to Maximize window using webDriver:


public void maximise() {
               
        Toolkit toolkit = Toolkit.getDefaultToolkit();

         Dimension screenResolution = new Dimension((int)
                         toolkit.getScreenSize().getWidth(), (int)
                         toolkit.getScreenSize().getHeight());

         driver.manage().window().setSize(screenResolution);

}


Method to Maximize window using WebDriverBackedSelenium:

By creating the instance of WebDriverBackedSelenium we can use seleniumRC methods inside webdriver.


                    {

WebDriver driver = new FirefoxDriver();

                    url = "http://www.freepdfconvert.com/";

                  

                   driver.get(url);

                  

                   Selenium selenium = new WebDriverBackedSelenium(driver, url);

                   selenium.windowMaximize();

                   selenium.waitForPageToLoad("30000");

 
               }

I hope these two methods will work for you as well.

Warm Regards,
Ranjith Manne.



Talwinder

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Mark Collin

unread,
Apr 27, 2012, 3:39:55 AM4/27/12
to webd...@googlegroups.com
No, you can however resize the window (SO you can emulate maximise by
resizing the window to the screen size).

harsha

unread,
Apr 27, 2012, 9:29:26 AM4/27/12
to webdriver
Hi I am using following code to maximize a window but it is not
working with Firefox 3.6.

driver.manage().window().maximize();

On Apr 27, 12:39 pm, "Mark Collin" <mark.col...@lazeryattack.com>
wrote:

Pawan Garia

unread,
Apr 27, 2012, 9:55:05 AM4/27/12
to webd...@googlegroups.com
Try this
you have to provide the dimensions for the window size to maximize and its working for me on firefox 3.6

 Webdriver d = new FirefoxDriver(profile);
EventFiringWebDriver driver = new EventFiringWebDriver(d);
//driver.Manage().Window.Size = new Size(1024, 768);
          
set the window size in dimensions object
Dimension dd = new Dimension(1024, 768);
        driver.manage().window().setSize(dd);
--
Regards-

PAWAN GARIA

darrell

unread,
Apr 27, 2012, 11:52:06 AM4/27/12
to webdriver
This is the solution I use. I find out what the current screen size is
and resize the browser to the size of the screen. Not really
maximizing the window but close enough for most people:

public void maximizeWindow() {
Point targetPosition = new Point(0, 0);
driver.manage().window().setPosition(targetPosition);
String w = "return screen.availWidth";
String h = "return screen.availHeight";
int width = ((Long)driver.executeScript(w)).intValue();
int height = ((Long)driver.executeScript(h)).intValue();
Dimension targetSize = new Dimension(width, height);
driver.manage().window().setSize(targetSize);
}

This works on the browser I test with.

On Apr 27, 3:39 am, "Mark Collin" <mark.col...@lazeryattack.com>
wrote:

Víctor Llorens Vilella

unread,
Apr 27, 2012, 12:04:17 PM4/27/12
to webd...@googlegroups.com
If maximize your window is not your exact goal, 

you can use awt Robot to keyPress and keyRelease (i.e. Windows key + D to minimize, Windows key + D again to restore window).
There's some usage:

robot = new Robot();
robot.keyPress(KeyEvent.VK_ALT);  
robot.keyPress(KeyEvent.VK_TAB);  
robot.keyRelease(KeyEvent.VK_TAB); 
robot.keyRelease(KeyEvent.VK_ALT); 


Hope it helps.
Víctor Llorens
--
Victor Llorens Vilella

Lukus

unread,
Apr 27, 2012, 12:52:31 PM4/27/12
to webd...@googlegroups.com
Victor, your example only shows clicking ALT+TAB... not sure how that would work, but I think you were just giving an example for the use of key presses.

If you want to use Robot to maximize, then this will work

//alt space x on windows maximizes
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_SPACE);

//release opposite order
robot.keyRelease(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_ALT);

robot.keyPress(KeyEvent.VK_X);
robot.keyRelease(KeyEvent.VK_X);

harsha

unread,
Apr 30, 2012, 7:47:54 AM4/30/12
to webdriver
Thanks a lot for all your replies..

It is working fine now . I am using following line
driver.manage().window().maximize();


Regards,
harsha

Talwinder singh

unread,
May 1, 2012, 12:49:03 AM5/1/12
to webdriver

HI,



I am able to do Maximize using

selenium.windowMaximize();

where selenium is a webdriverBackedSelenium instance , but still not
able to do Minimize.

Actually i need both the actions minimize and maximize to make sure
that the wend on which i am performing send key operations is in
focus .


I tried selenium.windowFocus() method but it doesn't seem to work.


By doing minimize and maximize operation the window will always come
in the foreground. So is there any way to minimize the browser
window ?

Regards,
Talwinder
Reply all
Reply to author
Forward
0 new messages