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.
- 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.
driver.manage().window().setPosition(new Point(-2000, 0))
- 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.
- Use the Robot class and windows shortcut keys for the same (as already mentioned by you).