How can I minimize the browser window which has been launched via Selenium Webdriver?

I see that there is a method to maximize (documentation), but I cannot find the converse for minimize.

I have tried resizing and repositioning the window, however this does not work the same way as minimize.

Is there a way to do this in Selenium? Or can this only be done through Robot key events (e.g. Windows + D) ?

  • Just curious why do you want to minimize? Do you want to test something works while minimized? OR? In the past I have had issues with not full-screen browsers. Leading to start each test with maximizing the browser at the start. Commented Nov 4, 2015 at 11:57
  • I don't really want to test anything while it is minimized. I was wondering why WebDriver have a maximize option, but not minimize. Also, I was recently asked this question in one of the interviews I attended. Commented Nov 4, 2015 at 12:30

6 Answers 6


Short answer to your question: Unfortunately, Selenium do not provide any built-in function for minimizing the browser window, there is only function for maximizing the window. But there are some work around for doing this.

  1. You want window to be out of sight, then you need to use this code. by using it browser window will be out of your sight and you will not be able to see what is running, but don't worry your test cases will keep on executing. It is tried and tested work around.

Reference Link

driver.manage().window().setPosition(new Point(-2000, 0))
  1. You can use PhantomJS for running your test cases, download and install it from this link and simply change the line

driver = webdriver.Firefox() to driver = webdriver.PhantomJS()

and you don't need to change any more code. Your browser will run in an hidden mode.

Reference link

  1. Use the Robot class and windows shortcut keys for the same (as already mentioned by you).
  • One more option might be to use 'HtmlUnitDriver' (on similar lines to PhantomJS). Commented Nov 5, 2015 at 2:16
  • Yes, that too is there but I thought that OP may be knowing about that.
    – Dhiman
    Commented Nov 5, 2015 at 2:23
  • Thanks a lot for the answer. I'm gonna try PhantomJS and see how it works. Commented Nov 5, 2015 at 5:20
  • why is everyone saying that? It's not true that phandomJS works with existing code and you don' t have to change anything.
    – veritaS
    Commented Nov 3, 2018 at 23:21

Perhaps, I have the wrong context here (the OP's documentation link is broken now), but I believe you can now minimize the window with webdriver.minimize_window().

Python Documentation


For C# language:


This works fine with Chrome, Firefox, IE but fails for 'Edge' driver.

  • Can you add a reference link of documentation! Commented Dec 5, 2018 at 5:19
  • @NawshadRehanRasha I couldn't find a proper documentation. It worked for me (in C#). I have some pictures of the code that I tried. Please check the link: github.com/priyanka-kondapuram/C-Sharp/issues/1
    – Priyanka
    Commented Dec 20, 2018 at 18:50

The best I'd say is to type shortcut using Robot Class. Shortcut to minimize: Alt+Space+N

    Robot robot=new Robot();

By using the above code you can minimize your browser.


You can also resize the window:

 Dimension n = new Dimension(360,592);  
driver.manage().window().setSize(new Dimension(1200,800));

This will works for you.

  • 1
    Can you elaborate why this is different than sameer's answer from Nov 19, 2015?
    – corsiKa
    Commented Mar 1, 2020 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.