FAQ

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

Talwinder singh
Apr 27, 2012 at 6:13 am
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

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

Search Discussions

9 responses

  • Ranjith Manne at Apr 27, 2012 at 7:04 am
    *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.



    On Fri, Apr 27, 2012 at 11:43 AM, Talwinder singh
    wrote:
    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

    --
    You received this message because you are subscribed to the Google Groups
    "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to
    webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/webdriver?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Mark Collin at Apr 27, 2012 at 7:40 am
    No, you can however resize the window (SO you can emulate maximise by
    resizing the window to the screen size).

    -----Original Message-----
    From: webdriver@googlegroups.com On
    Behalf Of Talwinder singh
    Sent: 27 April 2012 07:13
    To: webdriver
    Subject: [webdriver] Looking for a way to minimize and maximize browser
    window for IE, Firefox and chrome


    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

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


    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Harsha at Apr 27, 2012 at 1:29 pm
    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" wrote:
    No, you can however resize the window (SO you can emulate maximise by
    resizing the window to the screen size).

    -----Original Message-----
    From: webdriver@googlegroups.com On

    Behalf Of Talwinder singh
    Sent: 27 April 2012 07:13
    To: webdriver
    Subject: [webdriver] Looking for a way to minimize and maximize browser
    window for IE, Firefox and chrome

    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

    --
    You received this message because you are subscribed to the Google Groups
    "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to
    webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Pawan Garia at Apr 27, 2012 at 1:55 pm
    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);

    On Fri, Apr 27, 2012 at 6:59 PM, harsha wrote:

    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" wrote:
    No, you can however resize the window (SO you can emulate maximise by
    resizing the window to the screen size).

    -----Original Message-----
    From: webdriver@googlegroups.com On

    Behalf Of Talwinder singh
    Sent: 27 April 2012 07:13
    To: webdriver
    Subject: [webdriver] Looking for a way to minimize and maximize browser
    window for IE, Firefox and chrome

    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

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

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

    --
    Regards-

    PAWAN GARIA

    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Darrell at Apr 27, 2012 at 3:52 pm
    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" wrote:
    No, you can however resize the window (SO you can emulate maximise by
    resizing the window to the screen size).







    -----Original Message-----
    From: webdriver@googlegroups.com On

    Behalf Of Talwinder singh
    Sent: 27 April 2012 07:13
    To: webdriver
    Subject: [webdriver] Looking for a way to minimize and maximize browser
    window for IE, Firefox and chrome

    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

    --
    You received this message because you are subscribed to the Google Groups
    "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to
    webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Víctor Llorens Vilella at Apr 27, 2012 at 4:04 pm
    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
    On 27 April 2012 17:52, darrell wrote:

    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" wrote:
    No, you can however resize the window (SO you can emulate maximise by
    resizing the window to the screen size).







    -----Original Message-----
    From: webdriver@googlegroups.com On

    Behalf Of Talwinder singh
    Sent: 27 April 2012 07:13
    To: webdriver
    Subject: [webdriver] Looking for a way to minimize and maximize browser
    window for IE, Firefox and chrome

    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

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

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

    --
    Victor Llorens Vilella

    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Lukus at Apr 27, 2012 at 4:52 pm
    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);

    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/5r_QcdC9sFEJ.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Harsha at Apr 30, 2012 at 11:47 am
    Thanks a lot for all your replies..

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


    Regards,
    harsha
    On Apr 27, 9:52 pm, Lukus wrote:
    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);
    --
    You received this message because you are subscribed to the Google Groups "webdriver" group.
    To post to this group, send email to webdriver@googlegroups.com.
    To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
  • Talwinder singh at May 1, 2012 at 4:49 am
    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
    On Apr 30, 4:47 pm, harsha wrote:
    Thanks a lot for all your replies..

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

    Regards,
    harsha

    On Apr 27, 9:52 pm, Lukus wrote:






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

Related Discussions